The basics
You don't need to know GraphQL in depth to use the API. If it's new to you, the GraphQL section links to an introduction.
Your request
Endpoint
https://api.soundtrack.io/v2Every request goes to this one endpoint. Subscriptions use a WebSocket endpoint instead.
Token
-H 'Authorization: Basic your_token'Send the token you requested in Settings > API with Basic auth.
Keep your token secret and never ship it in client-side code, such as a frontend app or a public repository. We block any token we find exposed or compromised.
Content-Type
-H 'Content-Type: application/json'Send the request body as JSON.
Body
{
"query": "query NowPlaying($soundZone: ID!) { nowPlaying(soundZone: $soundZone) { track { title album { title display { image { size(width: 640, height: 640) } } } } } }",
"variables": { "soundZone": "sound_zone_id" },
"operationName": "NowPlaying"
}Every request is a POST with a JSON body of three fields:
queryis the GraphQL document: a query, a mutation or a subscription, given a name. Types of actions describes each.variablesholds the values the operation takes, such as IDs, so they stay out of the query text. See Parameterized queries.operationNamenames the operation to run. It's required when the document holds more than one operation, and worth sending every time, since named operations are easier to find in logs.
Requests and responses follow the GraphQL over HTTP specification, so any client built to it works with the API.
Our response
{
"data": {
"nowPlaying": {
"track": {
"title": "Sweet Addiction - Live Edit",
"album": {
"title": "Nous Horizon, Vol. 2 (Re-Works & Edits)",
"display": {
"image": {
"size": "https://l.cdnurl.com/image/31bbda8605500ba6345bd61941fd3cc536ad779"
}
}
}
}
}
}
}The API responds with JSON in the same shape as the query.
Soundtrack hierarchy
Before using the API, look around your Soundtrack account to see how its locations and zones are set up. Our help center has guides and FAQs for the app.
These are the concepts you'll meet in the API. The API calls a zone a SoundZone and a player a Device.
| Concept | In the API | Description |
|---|---|---|
| Account | Account | e.g. "Sven's Burgers". Can have multiple locations. |
| Location | Location | e.g. "Flagship Store, Stockholm". Can have multiple zones. |
| Zone | SoundZone | e.g. "Bar" or "Lobby". Plays through one player at a time. |
| Player | Device | One of the supported players. Needed to play music. |
| User | User | Can control one or many accounts. |
Each zone plays one stream of music. To play different music in different parts of a location, you need a zone, and a player, for each part.
For the same music everywhere in a location, one zone and one player are enough. Your audio system then carries the music to every speaker.
Each zone is billed as its own subscription.
Figuring out what you don't know
curl -XPOST https://api.soundtrack.io/v2 \
-H 'Authorization: Basic your_token' \
-H 'Content-Type: application/json' \
-d '{
"query": "query AccountsAndZones { me { ...on PublicAPIClient { accounts(first: 1) { edges { node { businessName locations(first: 1) { edges { node { name soundZones(first: 2) { edges { node { id name } } } } } } } } } } } }",
"operationName": "AccountsAndZones"
}'As the first query showed, a short query gets you what you need, as long as you know the ID, such as a zone's ID. To find the IDs, ask the API.
In this example, we want to know:
-
The
businessNameof the first account we have access to, such asSven's Burgers -
The
nameof that account's first location, such asFlagship Store, Stockholm -
The
idandnameof that location's first two zones, such asBarandLobby
This query introduces two new concepts:
-
The
meroot field, which returns what you have access to. -
Connections (
edges,nodeandfirst: 1), which let you page through lists.
Connections explains them.