Show examples in:
JavascriptHTTP
Content Management API > Environment

Fork an existing environment

Query parameters

immediate_returnboolean

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

fastboolean

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

forceboolean

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

Body parameters

idstringRequired

The ID of the forked environment

Example:"my-sandbox-env"
typestringRequired

Must be exactly "environment".

Returns

Returns a Job ID. You can then poll for thecompletion of the jobthat will eventually return a resource object of type environment

Examples

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

POST https://site-api.datocms.com/environments/:environment_id/fork HTTP/1.1
Authorization: Bearer YOUR-API-TOKEN
Accept: application/json
X-Api-Version: 3
Content-Type: application/vnd.api+json
{
"data": {
"type": "environment",
"id": "my-sandbox-env"
}
}
Terminal window
curl -g 'https://site-api.datocms.com/environments/:environment_id/fork' \
-X POST \
-H "Authorization: Bearer YOUR-API-TOKEN" \
-H "Accept: application/json" \
-H "X-Api-Version: 3" \
-H "Content-Type: application/vnd.api+json" \
--data-binary '{"data":{"type":"environment","id":"my-sandbox-env"}}'
await fetch("https://site-api.datocms.com/environments/:environment_id/fork", {
method: "POST",
headers: {
Authorization: "Bearer YOUR-API-TOKEN",
Accept: "application/json",
"X-Api-Version": "3",
"Content-Type": "application/vnd.api+json",
},
body: JSON.stringify({ data: { type: "environment", id: "my-sandbox-env" } }),
});
HTTP/1.1 202 Accepted
Content-Type: application/json
Cache-Control: cache-control: max-age=0, private, must-revalidate
X-RateLimit-Limit: 30
X-RateLimit-Remaining: 28
{
"data": {
"type": "job",
"id": "4235"
}
}

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:

GET https://site-api.datocms.com/job-results/:job_result_id HTTP/1.1
Authorization: Bearer YOUR-API-TOKEN
Accept: application/json
X-Api-Version: 3
Terminal window
curl -g 'https://site-api.datocms.com/job-results/:job_result_id' \
\
-H "Authorization: Bearer YOUR-API-TOKEN" \
-H "Accept: application/json" \
-H "X-Api-Version: 3"
await fetch("https://site-api.datocms.com/job-results/:job_result_id", {
headers: {
Authorization: "Bearer YOUR-API-TOKEN",
Accept: "application/json",
"X-Api-Version": "3",
},
});
HTTP/1.1 200 OK
Content-Type: application/json
Cache-Control: cache-control: max-age=0, private, must-revalidate
X-RateLimit-Limit: 30
X-RateLimit-Remaining: 28
{
"data": {
"type": "job_result",
"id": "34",
"attributes": {
"status": 200,
"payload": {
"data": {
"type": "environment",
"id": "main",
"meta": {
"status": "ready",
"created_at": "2020-04-21T07:57:11.124Z",
"read_only_mode": true,
"last_data_change_at": "2020-04-21T07:57:11.124Z",
"primary": true,
"forked_from": "main"
}
}
}
}
}
}