Subchapter 3.11
references/content-management/environments.mdMarkdown6 KBView on GitHub
Environments are isolated content workspaces within a space. Use them for staging, testing, and feature branches.
curl https://api.contentful.com/spaces/{space_id}/environments/{env_id} \
-H "Authorization: Bearer {cma_token}"Response includes sys.status.sys.id — one of: queued, creating, ready, failed.
curl https://api.contentful.com/spaces/{space_id}/environments \
-H "Authorization: Bearer {cma_token}"Creates an empty environment:
curl -X PUT https://api.contentful.com/spaces/{space_id}/environments/{env_id} \
-H "Authorization: Bearer {cma_token}" \
-H "Content-Type: application/vnd.contentful.management.v1+json" \
-d '{ "name": "Staging" }'Clone from a source environment by providing the source in the request body:
curl -X PUT https://api.contentful.com/spaces/{space_id}/environments/{new_env_id} \
-H "Authorization: Bearer {cma_token}" \
-H "Content-Type: application/vnd.contentful.management.v1+json" \
-d '{
"name": "Feature Branch",
"sourceEnvironmentId": "master"
}'This copies all content types and content from the source environment.
Environments are created asynchronously. Poll until status is ready:
# Poll GET until sys.status.sys.id === "ready"
curl https://api.contentful.com/spaces/{space_id}/environments/{env_id} \
-H "Authorization: Bearer {cma_token}"
# Check: response.sys.status.sys.id
# Possible values: "queued", "creating", "ready", "failed"curl -X PUT https://api.contentful.com/spaces/{space_id}/environments/{env_id} \
-H "Authorization: Bearer {cma_token}" \
-H "Content-Type: application/vnd.contentful.management.v1+json" \
-H "X-Contentful-Version: 1" \
-d '{ "name": "Updated Name" }'curl -X DELETE https://api.contentful.com/spaces/{space_id}/environments/{env_id} \
-H "Authorization: Bearer {cma_token}"Warning: This permanently deletes all content in the environment.
Aliases provide stable identifiers that point to different environments. Useful for zero-downtime deployments.
curl https://api.contentful.com/spaces/{space_id}/environment_aliases/{alias_id} \
-H "Authorization: Bearer {cma_token}"Response:
{
"sys": { "id": "master", "type": "EnvironmentAlias", "version": 1, ... },
"environment": {
"sys": { "type": "Link", "linkType": "Environment", "id": "production-v2" }
}
}curl https://api.contentful.com/spaces/{space_id}/environment_aliases \
-H "Authorization: Bearer {cma_token}"Point an alias to a different environment:
curl -X PUT https://api.contentful.com/spaces/{space_id}/environment_aliases/{alias_id} \
-H "Authorization: Bearer {cma_token}" \
-H "Content-Type: application/vnd.contentful.management.v1+json" \
-H "X-Contentful-Version: 1" \
-d '{
"environment": {
"sys": { "type": "Link", "linkType": "Environment", "id": "production-v3" }
}
}'# 1. Create new environment from current production
curl -X PUT https://api.contentful.com/spaces/{space_id}/environments/production-blue \
-H "Authorization: Bearer {cma_token}" \
-H "Content-Type: application/vnd.contentful.management.v1+json" \
-d '{"name":"Production Blue","sourceEnvironmentId":"master"}'
# 2. Wait for ready (poll until sys.status.sys.id === "ready")
# 3. Make changes in new environment
# 4. Switch alias to new environment
curl -X PUT https://api.contentful.com/spaces/{space_id}/environment_aliases/master \
-H "Authorization: Bearer {cma_token}" \
-H "Content-Type: application/vnd.contentful.management.v1+json" \
-H "X-Contentful-Version: 1" \
-d '{"environment":{"sys":{"type":"Link","linkType":"Environment","id":"production-blue"}}}'
# 5. Delete old environment after verification
curl -X DELETE https://api.contentful.com/spaces/{space_id}/environments/production-green \
-H "Authorization: Bearer {cma_token}"# 1. Create feature branch from master
curl -X PUT https://api.contentful.com/spaces/{space_id}/environments/feature-new-layout \
-H "Authorization: Bearer {cma_token}" \
-H "Content-Type: application/vnd.contentful.management.v1+json" \
-d '{"name":"New Layout Feature","sourceEnvironmentId":"master"}'
# 2. Wait for ready, make changes, test
# 3. Clean up when done
curl -X DELETE https://api.contentful.com/spaces/{space_id}/environments/feature-new-layout \
-H "Authorization: Bearer {cma_token}"sys.status.sys.id before using a new environment