# Queries and mutations


The Soundtrack API supports queries, subscriptions and mutations.

| Action                              | Example use case                                           |
| ----------------------------------- | ---------------------------------------------------------- |
| Queries                             | Fetch information that rarely changes (e.g. a zone's name) |
| [Subscriptions](/api/subscriptions) | Get updates when something changes (e.g. what's playing)   |
| Mutations                           | Make changes (e.g. skip to the next song)                  |

## Queries

```shell
curl -XPOST https://api.soundtrack.io/v2 \
-H 'Authorization: Basic your_token' \
-H 'Content-Type: application/json' \
-d '{
  "query": "query SoundZone($id: ID!) { soundZone(id: $id) { name id isPaired } }",
  "variables": {"id": "sound_zone_id"},
  "operationName": "SoundZone"
}'
```

> Response

```json
{
  "data": {
    "soundZone": {
      "name": "Staff room",
      "isPaired": true,
      "id": "U291bmRab25lLCwxanAzcjVsZTlkcy9m8v"
    }
  }
}
```

Use queries for information you don't expect to change often, such as a zone's ID, the account's name or a list of your locations.

Every query starts from a root field, such as `soundZone`, `account` or `me`. If you have the ID of your account or zone, pass it to the matching root field. If you don't, start with `me`, as [Figuring out what you don't know](/api/basics#figuring-out-what-you-dont-know) shows. The [API reference](/api/graphql-reference) lists every root query.

This example asks for a zone's name and ID, and whether a player is connected to it (`isPaired`).

## Mutations

```shell
curl -XPOST https://api.soundtrack.io/v2 \
-H 'Authorization: Basic your_token' \
-H 'Content-Type: application/json' \
-d '{
  "query": "mutation SetVolume($input: SetVolumeInput!) { setVolume(input: $input) { volume } }",
  "variables": {"input": {"soundZone": "sound_zone_id", "volume": 11}},
  "operationName": "SetVolume"
}'
```

> Response

```json
{
  "data": {
    "setVolume": {
      "volume": 11
    }
  }
}
```

Use mutations to make changes, such as setting the volume, skipping a song or pausing. [Licensing restrictions](/api#terms-of-use) limit who may control playback.

The [API reference](/api/graphql-reference) lists every mutation.

This example sets a zone's volume to 11. A mutation must select at least one field of its result, so it selects the volume.
