Using Curl Commands within the ZeroKey API (Windows)
Once you’ve generated an API or Bearer token using Postman, you can begin your integration by capturing the desired data.
Fetch, loop, and filter the Mobile data using curl and jq commands in the command prompt. Retrieve raw location data, filter for specific devices, and parse for specific fields such as Position, Orientation, and UsState and InsState flags. The following commands serve as examples to help you get started.
List of Commands
Fetching raw location data
Retrieve raw location data for all devices:
curl.exe -s -X GET "http://10.22.74.129:5000/v3/devices" -H "Authorization: Bearer JdYIZ2LzwCHM08+b9KHWOgGRnUpQUIrm5ohMBMrFOjE="
Looping raw location data
Continuously retrieve raw location data every 5 seconds:
@echo off & for /l %a in (1,0,2) do (curl.exe -s -X GET "http://10.22.74.129:5000/v3/devices" -H "Authorization: Bearer JdYIZ2LzwCHM08+b9KHWOgGRnUpQUIrm5ohMBMrFOjE=" & timeout /t 5 >nul)
Fetching data for a specific device
Filter and retrieve data for a specific device using its DeviceID (MAC address):
curl.exe -s -X GET "http://10.22.74.129:5000/v3/devices" -H "Authorization: Bearer JdYIZ2LzwCHM08+b9KHWOgGRnUpQUIrm5ohMBMrFOjE=" | jq ".[] | select(.DeviceID == \"D7:D7:87:05:CB:40\")"
This command selects only the device within the specified DeviceID from the API response.
Looping data for a specific device
Continuously monitor data for a specific Mobile:
@echo off & for /l %a in (1,0,2) do (curl.exe -s -X GET "http://10.22.74.129:5000/v3/devices" -H "Authorization: Bearer JdYIZ2LzwCHM08+b9KHWOgGRnUpQUIrm5ohMBMrFOjE=" | jq ".[] | select(.DeviceID == \"D7:D7:87:05:CB:40\")" & timeout /t 5 >nul)
This command runs continuously, fetching data for the Mobile every 5 seconds.
Parsing Mobile DeviceID, InsState, and Orientation
Extract and display only the Mobile’s DeviceID, InsState, and Orientation:
@echo off & for /l %a in (1,0,2) do (curl.exe -s -X GET "http://10.22.74.129:5000/v3/devices" -H "Authorization: Bearer JdYIZ2LzwCHM08+b9KHWOgGRnUpQUIrm5ohMBMrFOjE=" | jq ".[] | select(.DeviceID == \"D7:D7:87:05:CB:40\") | {DeviceID: .DeviceID, InsState: .InsState, Orientation: .Orientation}" & timeout /t 5 >nul)
Comprehensive parsing: UsState, InsState, Position and Orientation
Parse for DeviceID, UsState, InsState, Position, and Orientation:
@echo off & for /l %a in (1,0,2) do (curl.exe -s -X GET "http://10.22.74.129:5000/v3/devices" -H "Authorization: Bearer JdYIZ2LzwCHM08+b9KHWOgGRnUpQUIrm5ohMBMrFOjE=" | jq ".[] | select(.DeviceID == \"D7:D7:87:05:CB:40\") | {DeviceID: .DeviceID, UsState: .UsState, Position: .Position, InsState: .InsState, Orientation: .Orientation}" & timeout /t 5 >nul)
Monitoring a specific Mobile for UsState >= 3 and InsState >=3 with detailed data
Monitor a specific Mobile and only show data when both UsState and InsState are greater than or equal to 3, including additional fields like Position and Orientation:
@echo off & for /l %a in (1,0,2) do (curl.exe -s -X GET "http://10.22.74.129:5000/v3/devices" -H "Authorization: Bearer JdYIZ2LzwCHM08+b9KHWOgGRnUpQUIrm5ohMBMrFOjE=" | jq ".[] | select(.DeviceID == \"D7:D7:87:05:CB:40\" and .UsState >= 3 and .InsState >= 3) | {DeviceID: .DeviceID, UsState: .UsState, InsState: .InsState}" & timeout /t 5 >nul)
This command will continuously monitor and display high quality data only when both UsState and InsState are greater than or equal to 3.
Command Structure Overview
echo off
: Hides unnecessary output.for /l
(loop): Runs the command continuously every 5 seconds, and is adjustable.curl
with API Request: Fetches data from the device endpoint.jq
Filtering: Displays data only for the specific device. In the previous example, the device with the MAC address D7:D7:87:05:CB:40 when both UsState and InsState are 3.timeout
: Waits for 5 seconds before fetching data again, and is also adjustable.
Adjustment Steps
You can copy and paste the examples provided in this article into the command prompt, but be aware that a few steps need to be taken first.
Replace the IP address from this example with your own IP address:
curl.exe -s -X GET "http://<your_ip_address>:5000/v3/devices" -H "Authorization: Bearer <your_token>"
Replace the API token with a bearer token. A bearer token can be generated using the Postman application:
-H "Authorization: Bearer <your_token>"
For more information on how to generate a bearer token, please read our help article Establishing an API Connection and Obtaining a Bearer Token using Postman.
Replace <your_token> with your actual API bearer token.
This is required for authenticating your request when fetching data from the API.
How to adjust the device ID and filtering conditions
You can customize which device and data are filtered by modifying the following command:
select(.DeviceID == \"D7:D7:87:05:CB:40\" and .UsState >= 3 and .InsState >= 3)
Change the DeviceID: Update the MAC address D7:D7:87:05:CB:44 to match the DeviceID (MAC address) of your Mobile.
Adjust the loop interval
The loop interval controls how frequently the command runs. By default, it’s set to run every 5 seconds:
timeout /t 5 >nul
Change the 5 to your desired interval. For example:
The command
timeout /t 10 >nul
will cause the command to run every 10 seconds.The command
timeout /t 1 >nul
will run every second.