Show examples in:
Javascript HTTP

Content Management API > Environment

Fork an existing environment

Query parameters

immediate_return boolean

Whether the call should immediately return a pending environment, or wait for the completion of the fork

fast boolean

Performing a fast fork reduces processing time, but it also prevents writing to the source environment during the process

force boolean

Force the start of fast fork, even if there are collaborators editing some records

Body parameters

id string Required

The ID of the forked environment

Example: "my-sandbox-env"
type string Required

Must be exactly "environment".

Returns

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

Examples

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

1
POST https://site-api.datocms.com/environments/:environment_id/fork 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": "environment",
10
"id": "my-sandbox-env"
11
}
12
}
Terminal window
1
curl -g 'https://site-api.datocms.com/environments/:environment_id/fork' \
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":"environment","id":"my-sandbox-env"}}'
1
await fetch("https://site-api.datocms.com/environments/:environment_id/fork", {
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({ data: { type: "environment", id: "my-sandbox-env" } }),
10
});
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": "environment",
16
"id": "main",
17
"meta": {
18
"status": "ready",
19
"created_at": "2020-04-21T07:57:11.124Z",
20
"read_only_mode": true,
21
"last_data_change_at": "2020-04-21T07:57:11.124Z",
22
"primary": true,
23
"forked_from": "main"
24
}
25
}
26
}
27
}
28
}
29
}