# The basics


You don't need to know GraphQL in depth to use the API. If it's new to you, the [GraphQL section](/api/advanced#graphql) links to an introduction.

## Your request

### Endpoint

```shell
https://api.soundtrack.io/v2
```

Every request goes to this one endpoint. [Subscriptions](/api/subscriptions) use a WebSocket endpoint instead.

### Token

```shell
-H 'Authorization: Basic your_token'
```

Send the token you requested in [Settings > API](https://app.soundtrack.io/accounts/_/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

```shell
-H 'Content-Type: application/json'
```

Send the request body as JSON.

### Body

```json
{
  "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:

- `query` is the GraphQL document: a query, a mutation or a subscription, given a name. [Types of actions](/api/queries-and-mutations) describes each.
- `variables` holds the values the operation takes, such as IDs, so they stay out of the query text. See [Parameterized queries](/api/advanced#parameterized-queries).
- `operationName` names 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](https://http-spec.graphql.org/draft/), so any client built to it works with the API.

## Our response

```json
{
  "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](https://help.soundtrack.io) 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](https://help.soundtrack.io). 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

```shell
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](/api#your-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 `businessName` of the first account we have access to, such as `Sven's Burgers`

- The `name` of that account's first location, such as `Flagship Store, Stockholm`

- The `id` and `name` of that location's first two zones, such as `Bar` and `Lobby`

This query introduces two new concepts:

- The `me` root field, which returns what you have access to.

- Connections (`edges`, `node` and `first: 1`), which let you page through lists.

[Connections](/api/advanced#connections) explains them.
