Making API Requests
Managing and talking to your devices
The Senza platform offers an API that lets you perform tasks like managing your devices and sending a message to a group of devices or a single device.
The security model for the API uses bearer authentication, in which an API key consisting of a client ID and client secret are exchanged for an Access Token that is valid for a limited period of time for calling the API.
See the API Keys page for details on creating an API key.
Getting an access token
The bearer authentication page describes how to call the API to obtain an access token.
You'll want to make a POST request to https://auth.synamedia.com/oauth/token with the following header:
Content-Type: application/json
And body:
{
"client_id": "your_client_id",
"client_secret": "your_client_secret",
"audience": "<https://projects.synamedia.com">,
"grant_type": "client_credentials"
}
We have an interactive API explorer that lets you make requests directly in the developer documentation. You can try it here to obtain an access token.
Enter your client_id
and client_secret
that you saved in the previous step, along with the audience
and grant_type
as indicated. Click Try It! to call the API, and you'll receive a response like:
{
"access_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp...",
"scope": "hyperscale:messages:send-group",
"expires_in": 21600,
"token_type": "Bearer"
}
That indicates that the access token can be used for six hours to send group messages.
Sending a message
Now that we have an access token, let's try using it to send a message.
We can again use the API explorer to call the Group Messaging API.
First, make a note of your tenant ID in the operations console:
You'll want to make a POST request to https://hyperscale-message-broker-main.ingress.active.streaming.synamedia.com/message-broker/1.0/messages/tenant/{tenant_id}/groups/app (substituting your tenant ID in the URL path) with these headers:
Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZC...
Content-Type: application/json
And body:
{
"groups": ["A","B"],
"payload": {"content": {}},
"eventName": "SomeEvent"
}
The groups correspond to any groups that your web app has registered to receive messages for, and the payload can be any content that you want to send.
Go ahead and click Try It! to make the API call.
See the article on using Alarms and Messages to wake up the browser for details on receiving messages in your app.
Other ways to call the API
The API console has a code generation feature where you can select your favorite programming language and it will write some code for you to call the API on your platform of choice.
You may also find it useful to use an API client such as Postman or RapidAPI during development. The latter has a handy feature where you can automatically use part of the response of your API call in the request of another call, which will save you a lot of copying and pasting access tokens.
Tutorials
- Emergency Alerts is an end-to-end tutorial for sending group messages.
- Alarms and Messages
Updated 4 months ago