# Add a track to a collection

Add a track to a collection owned by the caller. The track is appended to the end of the collection. The operation is idempotent — adding a track that is already in the collection has no effect.

Returns `404` if the collection is not owned by the caller, or if the track does not exist or belongs to a different organization.

## Path parameters

**`organization_id`** string required

The organization that owns the collection.

**`collection_id`** string required

The collection id (`mcoll_`).

## Request Body

**`track_id`** string required

The id of the track to add (`mtrack_`).

## Returns

A mutation acknowledgement with `success`, `id` (the added track id), and `detail`.

Example

```bash cURL
curl -X POST "https://api.aitronos.com/v1/music/org_abc123/collections/mcoll_4a1f9c7e2b8d/tracks" \
  -H "X-API-Key: $FREDDY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "track_id": "mtrack_8d2e1f6a3c9b" }'
```


```python Python SDK
from aitronos import Aitronos  # pip install aitronos-sdk

client = Aitronos(api_key="your-api-key")

ack = client.post(
    "/v1/music/org_abc123/collections/mcoll_4a1f9c7e2b8d/tracks",
    json={"track_id": "mtrack_8d2e1f6a3c9b"},
)
print(ack["detail"])
```


```python Python
import os
import requests

api_key = os.environ["FREDDY_API_KEY"]

response = requests.post(
    "https://api.aitronos.com/v1/music/org_abc123/collections/mcoll_4a1f9c7e2b8d/tracks",
    headers={"X-API-Key": api_key},
    json={"track_id": "mtrack_8d2e1f6a3c9b"},
)

print(response.json()["detail"])
```


```javascript JavaScript
const apiKey = process.env.FREDDY_API_KEY;

const response = await fetch('https://api.aitronos.com/v1/music/org_abc123/collections/mcoll_4a1f9c7e2b8d/tracks', {
  method: 'POST',
  headers: {
    'X-API-Key': apiKey,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ track_id: 'mtrack_8d2e1f6a3c9b' }),
});

const ack = await response.json();
console.log(ack.detail);
```

**Response:**


```json 200 OK
{
  "success": true,
  "id": "mtrack_8d2e1f6a3c9b",
  "detail": "Track added to collection."
}
```

Errors

```json 401 Unauthorized
{
  "success": false,
  "error": {
    "code": "AUTHENTICATION_REQUIRED",
    "message": "Authentication required. Please provide a valid API key.",
    "system_message": "Missing or invalid authorization header",
    "type": "authentication_error",
    "status": 401,
    "details": {},
    "trace_id": "req_abc123xyz",
    "timestamp": "2026-06-28T10:30:00Z"
  }
}
```


```json 404 Not Found
{
  "success": false,
  "error": {
    "code": "RESOURCE_NOT_FOUND",
    "message": "The requested resource was not found.",
    "system_message": "Collection not owned by caller or track not found",
    "type": "client_error",
    "status": 404,
    "details": { "collection_id": "mcoll_4a1f9c7e2b8d", "track_id": "mtrack_8d2e1f6a3c9b" },
    "trace_id": "req_jkl012abc",
    "timestamp": "2026-06-28T10:30:00Z"
  }
}
```

## Related Resources

- [Remove a track from a collection](/docs/api-reference/music/remove-collection-track)
- [List a collection's tracks](/docs/api-reference/music/list-collection-tracks)
- [Reorder a collection](/docs/api-reference/music/reorder-collection)