How to send commands to devices using REST API
This guide will show you how to send commands to a device using REST API and how to send commands to multiple devices within a Tag.
Requisites
The Commands REST API resource requires the following information when using it:
- Read how to enable REST API
- Read how to generate the REST API token
- Read how to obtain an application ID
- Read how to obtain the userID from a user
- Read how to obtain the deviceID from a Tag of users
Resources used
- Commands > Get
- Commands > Post
See available commands
This step is optional, but helps to retrieve already available commands from the devices.
To see the available commands for a device follow these steps:
1. Log in to http://host_name/comGpsGate/api/v.1/test
Note: replace host_name with your actual server IP address or DNS name.
2. Click on the resource name GET/applications/...../commands> Try it out option.
3. Enter the following details:
- applicationid = the ID of the application. Read here how to obtain it.
- userid = the ID of the user with privileges to read those commands. Read here how to obtain it.
- deviceid = the ID of the device. You can obtain it the same way as applicationid, entering the username of the device instead. If you want to obtain the deviceID of multiple devices, Read how to obtain the deviceID from a Tag of users.
If the commands are available, they will be listed under the Response area
Sending the command
1. Log in to http://host_name/comGpsGate/api/v.1/test
Note: replace host_name with your actual server IP address or host name.
2. Click on the resource name POST/applications/...../commands> Try it out option.
3. Enter the following details:
- applicationid = the ID of the application. Read here how to obtain it.
- userid = the ID of the user with privileges to read those commands. Read here how to obtain it.
- deviceid = the ID of the device. You can obtain it the same way as applicationid, entering the username of the device instead. If you want to obtain the deviceID of multiple devices, Read how to obtain the deviceID from a Tag of users.
- command = the command you want to send to the device, for example:
{
"command": "getinfo"
}
Note: make sure your device is compatible with the command you try to send. Check your device documentation to send the right commands to your devices.
If the command was successful, you will see the 200 state and the Response below: