Device groups using the APIs
All methods for device groups are in the Device Directory API.
Generating an authorization token
Before you can send other requests, you need to log in and create an authorization token:
curl -X POST \
https://api.us-east-1.mbedcloud.com/auth/login \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d 'account=<your-account>&username=<your-username>&password=<your-password>'
Note: Include the authorization token as a header in all subsequent requests.
Creating a new group
Create a new group using POST /v3/device-groups/
. Include name, description, and other custom attributes in the body of the request:
curl -X POST \
https://api.us-east-1.mbedcloud.com/v3/device-groups/ \
-H 'Authorization: Bearer <your-token>' \
-H 'Content-Type: application/json' \
-d '{
"name": "test",
"description": "This is my test group.",
"custom_attribute": "1"
}'
Deleting a group
Delete a group using DELETE /v3/device-groups/{device-group-id}/
:
curl -X DELETE \
https://api.us-east-1.mbedcloud.com/v3/device-groups/<device-group-id>/ \
-H 'Authorization: Bearer <your-token>' \
Listing all groups
See a list of all created groups using GET /v3/device-groups
:
curl -X GET \
https://api.us-east-1.mbedcloud.com/v3/device-groups/ \
-H 'Authorization: Bearer <your-token>' \
Showing a specific group
See information, including custom attributes, for a specific group using GET /v3/device-groups/{device-group-id}
:
curl -X GET \
https://api.us-east-1.mbedcloud.com/v3/device-groups/ \
-H 'Authorization: Bearer <your-token>' \
Modifying group attributes
Change group attributes like name
, description
, and so on using PUT /v3/device-groups/{device-group-id}/
. Include these attributes in the body of the request:
curl -X PUT \
https://api.us-east-1.mbedcloud.com/v3/device-groups/<device-group-id>/ \
-H 'Authorization: Bearer <your-token>' \
-H 'Content-Type: application/json' \
-d '{
"custom_attributes":
"hello" : "hi"
}
}'
Adding devices to a group
Add a device to a group using POST /v3/device-groups/{device-group-id}/devices/add/
:
curl -X POST \
https://api.us-east-1.mbedcloud.com/v3/device-groups/<device-group-id>/devices/add/ \
-H 'Authorization: Bearer <your-token>' \
-H 'Content-Type: application/json' \
-d '{
id : "<device-id>"
}'
Note: You must send a request for each device you want to add or remove.
Showing devices in a specific group
See a list of devices in a particular group using GET /v3/device-groups/{device-group-id}/devices/
:
curl -X GET \
https://api.us-east-1.mbedcloud.com/v3/device-groups/<device-group-id>/devices/ \
-H 'Authorization: Bearer <your-token>' \
Removing devices from a group
Remove a specific device from a group with POST /v3/device-groups/{device-group-id}/devices/remove/
. Include the device ID in the body of the request:
curl -X POST \
'https://api.us-east-1.mbedcloud.com/v3/device-groups/<device-group-id>/devices/remove/' \
-H 'Authorization: Bearer <your-token>' \