mirror of
https://github.com/micromdm/micromdm/
synced 2026-08-06 17:53:14 +08:00
add ngrok developemnt and curl request helpers (#392)
This commit is contained in:
54
tools/api/README.md
Normal file
54
tools/api/README.md
Normal file
@@ -0,0 +1,54 @@
|
||||
A sample of the common API requests are available as `curl` scripts. To use them, install all the requirements and follow the steps as described.
|
||||
|
||||
## Requirements
|
||||
|
||||
- [jq](https://stedolan.github.io/jq/)
|
||||
`brew install jq`
|
||||
|
||||
## Setup
|
||||
Create an `env` file and define environment variables you will need to talk to the server.
|
||||
This env file will be sourced by the scripts.
|
||||
|
||||
Contents of `env` file:
|
||||
```
|
||||
# the value of the -api-key flag that MicroMDM was started with.
|
||||
export API_TOKEN=supersecret
|
||||
export SERVER_URL=https://mdm.acme.co
|
||||
```
|
||||
|
||||
In your shell, set the environment variable `MICROMDM_ENV_PATH` to point to your env file.
|
||||
Do this every time you open a new shell to work with the scripts in this folder.
|
||||
```
|
||||
export MICROMDM_ENV_PATH="$(pwd)/env"
|
||||
```
|
||||
|
||||
## Usage examples
|
||||
|
||||
```
|
||||
# get all devices from micromdm. returns JSON.
|
||||
./tools/api/get_devices
|
||||
|
||||
# use jq to filter response. For example, to get the udid of the first device.
|
||||
./tools/api/get_devices | jq .devices[0].udid -r
|
||||
|
||||
# send a push notification to a device UDID
|
||||
./tools/api/send_push_notification <device-udid>
|
||||
|
||||
# combine sending a push notification with the get devices request.
|
||||
$udid=(tools/api/get_devices |jq .devices[0].udid -r)
|
||||
./tools/api/send_push_notification $udid
|
||||
```
|
||||
|
||||
The `api` folder groups all MDM commands in the `commands` folder. Use these for scheduling commands against a remote device. All of these take the device udid as a first argument and might take additional arguments when necessary.
|
||||
|
||||
```
|
||||
# install a configuration profile
|
||||
./tools/api/commands/install_profile $udid /path/to/profile.mobileconfig
|
||||
|
||||
# remove a configuration profile
|
||||
./tools/api/commands/remove_profile $udid Your-Profile-PayloadIdentifier
|
||||
```
|
||||
|
||||
All the scripts in this folder are tiny. Consider reading them to get an understanding of the API.
|
||||
Also consider learning `jq`.
|
||||
MicroMDM returns and accepts JSON for all of the API endpoints, and `jq` is a powerful tool for reading and manipulating JSON data.
|
||||
12
tools/api/commands/device_lock
Executable file
12
tools/api/commands/device_lock
Executable file
@@ -0,0 +1,12 @@
|
||||
#!/bin/bash
|
||||
source $MICROMDM_ENV_PATH
|
||||
endpoint="v1/commands"
|
||||
jq -n \
|
||||
--arg request_type "DeviceLock" \
|
||||
--arg udid "$1" \
|
||||
--arg pin $2 \
|
||||
'.udid = $udid
|
||||
|.pin = $pin
|
||||
|.request_type = $request_type
|
||||
'|\
|
||||
curl -u "micromdm:$API_TOKEN" "$SERVER_URL/$endpoint" -d@-
|
||||
12
tools/api/commands/install_profile
Executable file
12
tools/api/commands/install_profile
Executable file
@@ -0,0 +1,12 @@
|
||||
#!/bin/bash
|
||||
source $MICROMDM_ENV_PATH
|
||||
endpoint="v1/commands"
|
||||
jq -n \
|
||||
--arg request_type "InstallProfile" \
|
||||
--arg udid "$1" \
|
||||
--arg payload $(cat $2|base64) \
|
||||
'.udid = $udid
|
||||
|.payload = $payload
|
||||
|.request_type = $request_type
|
||||
'|\
|
||||
curl -u "micromdm:$API_TOKEN" "$SERVER_URL/$endpoint" -d@-
|
||||
12
tools/api/commands/remove_profile
Executable file
12
tools/api/commands/remove_profile
Executable file
@@ -0,0 +1,12 @@
|
||||
#!/bin/bash
|
||||
source $MICROMDM_ENV_PATH
|
||||
endpoint="v1/commands"
|
||||
jq -n \
|
||||
--arg request_type "RemoveProfile" \
|
||||
--arg udid "$1" \
|
||||
--arg identifier $2 \
|
||||
'.udid = $udid
|
||||
|.identifier = $identifier
|
||||
|.request_type = $request_type
|
||||
'|\
|
||||
curl -u "micromdm:$API_TOKEN" "$SERVER_URL/$endpoint" -d@-
|
||||
10
tools/api/commands/restart_device
Executable file
10
tools/api/commands/restart_device
Executable file
@@ -0,0 +1,10 @@
|
||||
#!/bin/bash
|
||||
source $MICROMDM_ENV_PATH
|
||||
endpoint="v1/commands"
|
||||
jq -n \
|
||||
--arg request_type "RestartDevice" \
|
||||
--arg udid "$1" \
|
||||
'.udid = $udid
|
||||
|.request_type = $request_type
|
||||
'|\
|
||||
curl -u "micromdm:$API_TOKEN" "$SERVER_URL/$endpoint" -d@-
|
||||
4
tools/api/get_devices
Executable file
4
tools/api/get_devices
Executable file
@@ -0,0 +1,4 @@
|
||||
#!/bin/bash
|
||||
source $MICROMDM_ENV_PATH
|
||||
endpoint="v1/devices"
|
||||
curl -s -u "micromdm:$API_TOKEN" "$SERVER_URL/$endpoint"
|
||||
5
tools/api/send_push_notification
Executable file
5
tools/api/send_push_notification
Executable file
@@ -0,0 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
source $MICROMDM_ENV_PATH
|
||||
endpoint="push"
|
||||
curl -u "micromdm:$API_TOKEN" "$SERVER_URL/$endpoint/$1"
|
||||
Reference in New Issue
Block a user