The following article describes how the REST based API for LoRaWAN Portal works and provides examples of the most basic API calls.
Online Documentation
The online documentation of the REST API contains information regarding all exposed calls, their parameters and possible return values. The online documentation generated by Swagger can be found here:
https://api.blink.services/Login
The first thing to do when using the API is to login with username and password to retrieve a token for subsequent API calls.
URL: https://api.blink.services/rest/core/login/{username}
Method: POST
Body: {"password": "mysecretpassword" }This call will always return a 200 OK, the result will contain if successful or not. If successful the token will be sent back and must be added as a request header “Authorization” with value “Bearer TOKEN" in subsequent calls. The token is usually valid for 12 hours.
Request example:
curl \
'https://api.blink.services/rest/core/login/user1' \
-X POST \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-d '{"password": "mysecretpassword"}'
| Invoke-WebRequest `
-Uri "https://api.blink.services/rest/core/login/user1" `
-Method 'POST' `
-Headers @{'Accept' = 'application/json'; 'Content-Type' = 'application/json'} `
-Body '{"password":"mysecretpassword"}' `
| Select-Object -Expand RawContent
|
Response (token shortened for readability):
{
"success": true,
"status": "SUCCESS",
"message": null,
"firstName": "John",
"lastName": "Doe",
"functions": [..],
"token": "eyJzdWIiOiJjb...JVjlg-HIYJmQ"
}
Subsequent calls must have the following request header added for authorization to work:
curl \
'https://api.blink.services/rest/net/user' \
-X GET \
-H 'Accept: application/json' \
-H 'Authorization: Bearer eyJzdWIiOiJjb...JVjlg-HIYJmQ'
| Invoke-WebRequest `
-Uri "https://api.blink.services/rest/net/user" `
-Method 'GET' `
-Headers @{'Accept' = 'application/json'; 'Authorization' = 'Bearer eyJzdWIiOiJjb...JVjlg-HIYJmQ'} `
| Select-Object -Expand RawContent
|
Request List of all Sensors
All sensors available to the current user can be retrieved with the following call:
URL: https://api.blink.services/rest/net/sensors
Method: GETRequest example:
curl \
'https://api.blink.services/rest/net/sensors' \
-X GET \
-H 'Accept: application/json' \
-H 'Authorization: Bearer eyJzdWIiOiJjb...JVjlg-HIYJmQ'
| Invoke-WebRequest `
-Uri "https://api.blink.services/rest/net/sensors" `
-Method 'GET' `
-Headers @{'Accept' = 'application/json'; 'Authorization' = 'Bearer eyJzdWIiOiJjb...JVjlg-HIYJmQ'} `
| Select-Object -Expand RawContent
|
Request List of some Sensors
Searches for specific sensors:
URL: https://api.blink.services/rest/net/sensors/search
Method: POSTRequest example:
curl \
'https://api.blink.services/rest/net/sensors/search' \
-X POST \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer eyJzdWIiOiJjb...JVjlg-HIYJmQ' \
--data '{
"provisioned": true,
"serialNumber": "1234"
}'
| Invoke-WebRequest `
-Uri "https://api.blink.services/rest/net/sensors" `
-Method 'POST' `
-Headers @{'Accept' = 'application/json'; 'Content-Type' = 'application/json'; 'Authorization' = 'Bearer eyJzdWIiOiJjb...JVjlg-HIYJmQ'} `
-Body (ConvertTo-Json @{
provisioned=true;
serialNumber="1234"
}) `
| Select-Object -Expand RawContent
|
Request Information on a Sensor
Additional information on a sensor use may also be requested
URL: https://api.blink.services/rest/net/sensors/{devEui}
Method: GETRequest example:
curl \
'https://api.blink.services/rest/net/sensors/70B3D52B10000004' \
-X GET \
-H 'Accept: application/json' \
-H 'Authorization: Bearer eyJzdWIiOiJjb...JVjlg-HIYJmQ'
| Invoke-WebRequest `
-Uri "https://api.blink.services/rest/net/sensors/70B3D52B10000004" `
-Method 'GET' `
-Headers @{'Accept' = 'application/json'; 'Authorization' = 'Bearer eyJzdWIiOiJjb...JVjlg-HIYJmQ'} `
| Select-Object -Expand RawContent
|
Request Values from a Sensor
Sensor values for a specific sensor can be retrieved for a date interval. If the parameters fromDate (inclusive) or toDate (exclusive) are left out, they default to yesterday or tomorrow. The interval may never exceed 31 days per request. If you need to fetch values for several sensors, please don’t make the requests in parallel.
URL: https://api.blink.services/rest/net/sensors/{devEui}/values?fromDate=YYYY-MMDD&toDate=YYYY-MM-DD
Method: GETRequest with no date interval (retrieve all values since yesterday)
curl \
'https://api.blink.services/rest/net/sensors/70B3D52B10000004/values' \
-X GET \
-H 'Accept: application/json' \
-H 'Authorization: Bearer eyJzdWIiOiJjb...JVjlg-HIYJmQ'
| Invoke-WebRequest `
-Uri "https://api.blink.services/rest/net/sensors/70B3D52B10000004/values" `
-Method 'GET' `
-Headers @{'Accept' = 'application/json'; 'Authorization' = 'Bearer eyJzdWIiOiJjb...JVjlg-HIYJmQ'} `
| Select-Object -Expand RawContent
|
Request with date interval
curl \
'https://api.blink.services/rest/net/sensors/70B3D52B10000004/values?
fromDate=2023-04-18&toDate=2023-04-19' \
-X GET \
-H 'Accept: application/json' \
-H 'Authorization: Bearer eyJzdWIiOiJjb...JVjlg-HIYJmQ'
| Invoke-WebRequest `
-Uri "https://api.blink.services/rest/net/sensors/70B3D52B10000004/values?fromDate=2023-04-18&toDate=2023-04-19" `
-Method 'GET' `
-Headers @{'Accept' = 'application/json'; 'Authorization' = 'Bearer eyJzdWIiOiJjb...JVjlg-HIYJmQ'} `
| Select-Object -Expand RawContent
|
Create a Sensor
Register the sensor in the portal.
URL: https://api.blink.services/rest/net/sensors/
Method: POSTRequest example:
curl \
'https://api.blink.services/rest/net/sensors/' \
-X POST \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer eyJzdWIiOiJjb...JVjlg-HIYJmQ' \
--data '{
"devEui": "70B3D52B10000004",
"active": true,
"installed": true,
"sensorActivationMethodTypeCompositeCode": "OTAA@SENSOR_COMMON",
"sensorClassTypeCompositeCode": "CLASS_A@SENSOR_COMMON",
"sensorTypeCompositeCode": "OTHER@SENSOR_COMMON",
"serviceProviderCode": "MY_COMPANY",
"customerCode": null,
"priceModelMessagesCountTypesCompositeCode": "25_144@SENSOR_COMMON",
"exportConfigCode": "DEFAULT_ACTIVEMQ",
"serialNumber": "1234"
}'
| Invoke-WebRequest `
-Uri "https://api.blink.services/rest/net/sensors" `
-Method 'POST' `
-Headers @{'Accept' = 'application/json'; 'Content-Type' = 'application/json'; 'Authorization' = 'Bearer eyJzdWIiOiJjb...JVjlg-HIYJmQ'} `
-Body (ConvertTo-Json @{
devEui="70B3D52B10000006";
active=true;
installed=true;
sensorActivationMethodTypeCompositeCode="OTAA@SENSOR_COMMON";
sensorClassTypeCompositeCode="CLASS_A@SENSOR_COMMON";
sensorTypeCompositeCode="OTHER@SENSOR_COMMON";
serviceProviderCode="BLINKSERVICES";
customerCode=$null;
priceModelMessagesCountTypesCompositeCode="25_144@SENSOR_COMMON";
exportConfigCode="DEFAULT_ACTIVEMQ";
serialNumber="1234"
}) `
| Select-Object -Expand RawContent
|
Provision a Sensor
Registers the sensor in the LoRaWAN network so it will be able to communicate.
URL: https://api.blink.services/rest/net/sensors/{devEui}/provision
Method: POSTRequest example:
curl \
'https://api.blink.services/rest/net/sensors/70B3D52B10000004/provision' \
-X POST \
-H 'Accept: application/json' \
-H 'Authorization: Bearer eyJzdWIiOiJjb...JVjlg-HIYJmQ'
| Invoke-WebRequest `
-Uri "https://api.blink.services/rest/net/sensors/70B3D52B10000004/provision" `
-Method 'POST' `
-Headers @{'Accept' = 'application/json'; 'Authorization' = 'Bearer eyJzdWIiOiJjb...JVjlg-HIYJmQ'} `
| Select-Object -Expand RawContent
|