Show examples in:
Javascript HTTP
Endpoint info
Available examples

Content Management API > Upload track

Create a new upload track

Body parameters

type string Required

Must be exactly "upload_track".

attributes.url_or_upload_request_id string Required

Either an URL to download, or the ID of an upload request

Example: "/7/1455102967-image.png"
attributes.type enum Required

The type of track (audio or subtitles)

Example: "subtitles"
subtitles Optional

Subtitles

audio Optional

Audio

attributes.language_code string Required

A valid BCP 47 specification compliant language code

Example: "it-IT"
attributes.name string Optional

The human-readable name of the track

Example: "Italiano"
attributes.closed_captions null, boolean Optional

Indicates if the track provides subtitles for the Deaf or Hard-of-hearing (SDH)

Returns

Returns a Job ID. You can then poll for the completion of the job that will eventually return a resource object of type upload_track

Examples

The response contains the ID of the asynchronous job that started:

1
POST https://site-api.datocms.com/uploads/:upload_id/tracks HTTP/1.1
2
Authorization: Bearer YOUR-API-TOKEN
3
Accept: application/json
4
X-Api-Version: 3
5
Content-Type: application/vnd.api+json
6
7
{
8
"data": {
9
"type": "upload_track",
10
"attributes": {
11
"url_or_upload_request_id": "/7/1455102967-image.png",
12
"type": "subtitles",
13
"language_code": "it-IT"
14
}
15
}
16
}
Terminal window
1
curl -g 'https://site-api.datocms.com/uploads/:upload_id/tracks' \
2
-X POST \
3
-H "Authorization: Bearer YOUR-API-TOKEN" \
4
-H "Accept: application/json" \
5
-H "X-Api-Version: 3" \
6
-H "Content-Type: application/vnd.api+json" \
7
--data-binary '{"data":{"type":"upload_track","attributes":{"url_or_upload_request_id":"/7/1455102967-image.png","type":"subtitles","language_code":"it-IT"}}}'
1
await fetch("https://site-api.datocms.com/uploads/:upload_id/tracks", {
2
method: "POST",
3
headers: {
4
Authorization: "Bearer YOUR-API-TOKEN",
5
Accept: "application/json",
6
"X-Api-Version": "3",
7
"Content-Type": "application/vnd.api+json",
8
},
9
body: JSON.stringify({
10
data: {
11
type: "upload_track",
12
attributes: {
13
url_or_upload_request_id: "/7/1455102967-image.png",
14
type: "subtitles",
15
language_code: "it-IT",
16
},
17
},
18
}),
19
});
1
HTTP/1.1 202 Accepted
2
Content-Type: application/json
3
Cache-Control: cache-control: max-age=0, private, must-revalidate
4
X-RateLimit-Limit: 30
5
X-RateLimit-Remaining: 28
6
7
{
8
"data": {
9
"type": "job",
10
"id": "4235"
11
}
12
}

To get the asynchronous job result, poll the job result endpoint. While the task is in progress, the endpoint returns a 404 status code. When the job completes, the status changes to 200 OK:

1
GET https://site-api.datocms.com/job-results/:job_result_id HTTP/1.1
2
Authorization: Bearer YOUR-API-TOKEN
3
Accept: application/json
4
X-Api-Version: 3
Terminal window
1
curl -g 'https://site-api.datocms.com/job-results/:job_result_id' \
2
\
3
-H "Authorization: Bearer YOUR-API-TOKEN" \
4
-H "Accept: application/json" \
5
-H "X-Api-Version: 3"
1
await fetch("https://site-api.datocms.com/job-results/:job_result_id", {
2
headers: {
3
Authorization: "Bearer YOUR-API-TOKEN",
4
Accept: "application/json",
5
"X-Api-Version": "3",
6
},
7
});
1
HTTP/1.1 200 OK
2
Content-Type: application/json
3
Cache-Control: cache-control: max-age=0, private, must-revalidate
4
X-RateLimit-Limit: 30
5
X-RateLimit-Remaining: 28
6
7
{
8
"data": {
9
"type": "job_result",
10
"id": "34",
11
"attributes": {
12
"status": 200,
13
"payload": {
14
"data": {
15
"type": "upload_track",
16
"id": "xBe7u01029ipxBLQhYzZCJ1cke01zCkuUsgnYtH0017nNzbpv2YcsoMDmw",
17
"attributes": {
18
"type": "subtitles",
19
"name": "Italiano",
20
"language_code": "it-IT",
21
"closed_captions": false,
22
"status": "ready",
23
"error": null
24
},
25
"relationships": {
26
"upload": {
27
"data": {
28
"type": "upload",
29
"id": "q0VNpiNQSkG6z0lif_O1zg"
30
}
31
}
32
}
33
}
34
}
35
}
36
}
37
}