Skip to main content

Pull API endpoints

Introduction

The Astrocast API allows you to programmatically interact with the Astrocast backend platform, retrieve your device messages, and automate the deployment of your devices in the field. You can retrieve your data in JSON or CSV format.

API Reference

The Astrocast API Reference is available on: https://api.astrocast.com.

API Request Headers

KeyValueRequired
x-api-keySee Access TokensYes
Acceptapplication/json (default) or text/csvOptional

API Response Codes

Our API endpoints return standard response codes, such as:

Status CodeTextDescription
200AcceptedThe request was successful and data was returned.
400Bad requestThe request was unacceptable, often due to incorrect parameters, or a missing required parameter.
401UnauthorizedThe API key and/or secret is not valid.
404Not foundThe requested resource does not exist.
503Not availablePlease 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.

You can create and manage your access tokens in the Astrocast Portal.

Message encoding

The data property in the Messages and Commands API endpoints is the payload of your message. It is encoded in base64.

To decode your message in Python, you can use the following:

message = base64.b64decode(data).hex()

To decode your message in Node.js, you can use the following:

'use strict';

let data = 'R3JvdW5kIENvbnRyb2wgdG8gTWFqb3IgVG9tISAyMS4wMA==';

let buff = Buffer.from(data, 'base64');
let message = buff.toString('utf-8');

console.log(text);

Request Examples

Python

import requests, base64
from datetime import datetime, timedelta

apiToken = "FVquFITiVsu3RJ6KbkigpOJccmQFUqMwo6ftCaiWoXXvkyutWZ7t3veZmost1nxEO6OUEMiabu0BZn0N1wR3ssB11ohoRX4a"
startReceivedDate = datetime.now() - timedelta(minutes=60)

response = requests.get("https://api.astrocast.com/v1/messages?startReceivedDate=" + str(startReceivedDate.strftime("%Y-%m-%dT%H:%M:%S")), headers={"X-Api-Key":str(apiToken)})
if response.status_code == 200:
if len(response.json()) > 0:
for message in response.json():
deviceGuid = str(message['deviceGuid'])
messageGuid = str(message['messageGuid'])
latitude = message['latitude']
longitude = message['longitude']
payload = base64.b64decode(message['data']).hex()
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 = '2022-08-01T01:00:00.00';

fetch('https://api.astrocast.com/v1/messages?startReceivedDate=' + startReceivedDate + '&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.');
});