Astrocast API
Introduction
The Astrocast API allows you to programmatically interact with the Astrocast backend platform, to retrieve your device messages, and to automate the deployment of your devices in the field. You can retrieve your data in JSON or CSV format.
API Reference
The API Reference is available on the following platform: https://api.astrocast.com.
API Request Headers
Key | Value | Required |
---|---|---|
x-api-key | See Access Tokens | Yes |
Accept | application/json (default) or text/csv | Optional |
API Response Codes
Below is a list of typical response codes of the API:
Status Code | Text | Description |
---|---|---|
200 | Accepted | The request was successful and data has been returned. |
400 | Bad request | The request was unacceptable, often due to incorrect parameters or a missing required parameter. |
401 | Unauthorized | The API key and secret is not valid. |
404 | Not found | The requested resource does not exist. |
503 | Not available | Please retry later. A "try after" period of 15 minutes defined in seconds is returned in the response. |
Access Tokens
API access tokens are the credentials needed to access the Astrocast API.
These tokens are managed in the Astrocast Portal.
Message encoding
The data
field of the Messages and Commands API (which is the payload of your message) is encoded in base64.
To decode the message in Python you can use the following function:
message = base64.b64decode(data).hex()
To decode the message in Node.js you can use the following function:
'use strict';
let data = 'R3JvdW5kIENvbnRyb2wgdG8gTWFqb3IgVG9tISAyMS4wMA==';
let buff = Buffer.from(data, 'base64');
let message = buff.toString('utf-8');
console.log(text);
Request Examples
Python
import json, requests, sys
apiToken = "FVquFITiVsu3RJ6KbkigpOJccmQFUqMwo6ftCaiWoXXvkyutWZ7t3veZmost1nxEO6OUEMiabu0BZn0N1wR3ssB11ohoRX4a"
deviceGuid = "c984ff2b-e4d0-417f-8ea3-11d74a55d251"
startReceivedDate = "2020-12-01T01:00:00.00"
endReceivedDate = "2020-12-31T01:00:00.00"
response = requests.get("https://api.astrocast.com/v1/messages?startReceivedDate=" + str(startReceivedDate) + "&endReceivedDate=" + str(endReceivedDate) + "&deviceGuid=" + str(deviceGuid), headers={"X-Api-Key":str(apiToken)})
if response.status_code == 200:
if len(response.json()) > 0:
print(str(response.json()))
else:
print("There is no message.")
else:
print("Error, something is wrong in the request.")
Javascript
var apiToken = 'FVquFITiVsu3RJ6KbkigpOJccmQFUqMwo6ftCaiWoXXvkyutWZ7t3veZmost1nxEO6OUEMiabu0BZn0N1wR3ssB11ohoRX4a';
var deviceGuid = 'c984ff2b-e4d0-417f-8ea3-11d74a55d251';
var startReceivedDate = '2020-12-01T01:00:00.00';
var endReceivedDate = '2020-12-31T01:00:00.00';
fetch('https://api.astrocast.com/v1/messages?startReceivedDate=' + startReceivedDate + '&endReceivedDate=' + endReceivedDate + '&deviceGuid=' + deviceGuid, {
method: 'GET',
headers: {
'X-Api-Key': apiToken
}
})
.then(response => {
data = response.json();
console.log(data);
})
.catch(error => {
console.log('Error, something is wrong in the request.');
});