> For clean Markdown of any page, append .md to the page URL. > For a complete documentation index, see https://contentful.com/developers/docs/llms.txt. > For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://contentful.com/_mcp/server. # Create an environment POST https://api.contentful.com/spaces/{space_id}/environments Content-Type: application/vnd.contentful.management.v1+json Creates a new environment, optionally cloned from a source environment via `X-Contentful-Source-Environment`. Use a specified ID for automation — auto-generated IDs are not recommended. Reference: https://contentful.com/developers/docs/references/content-management-api/environments/create-an-environment ## Authentication - `Authorization` header (bearer token, required) — Bearer authentication of the form `Bearer `, where token is your auth token. ## Request ### Path parameters - `space_id` (string, required) — ID of the space in form of a string ### Headers - `X-Contentful-Source-Environment` (string, optional) — Environment ID for the desired source environment. You can create an environment with any other environment as a source by providing this header. ### Body (application/vnd.contentful.management.v1+json) This endpoint expects a map from string to any. - `map from string to any` ## Response ### 201 Created - Resource created successfully - `map from string to any` ## Examples **Request** ```json { "name": "Staging" } ``` **Response** ```json { "sys": { "createdAt": "2025-09-09T18:42:24.000Z", "createdBy": { "sys": { "id": "7BslKh9TdKGOK41VmLDjFZ", "linkType": "User", "type": "Link" } }, "id": "staging", "space": { "sys": { "id": "yadj1kx9rmg0", "linkType": "Space", "type": "Link" } }, "type": "Environment", "updatedAt": "2025-09-09T18:42:24.000Z", "updatedBy": { "sys": { "id": "4FLrUHftHW3v2BLi9fzfjU", "linkType": "User", "type": "Link" } }, "version": 1 } } ``` **SDK Code** ```android Android // Create the Contentful client. final CMAClient client = new CMAClient .Builder() .setAccessToken("") .setSpaceId("") .setEnvironmentId("") .build(); // Create a local environment. final CMAEnvironment environment = new CMAEnvironment() .setName("name"); // Create the same environment in Contentful. client .environments() .async() .create( "", environment, new CMACallback() { @Override protected void onSuccess(CMAEnvironment environment) { // Successfully created a new entry. new AlertDialog.Builder(context) .setTitle("Contentful") .setMessage("Creation of an environment was successful." + "\n\nResult: " + environment) .show(); } @Override protected void onFailure(RuntimeException exception) { // An error occurred! Inform the user. new AlertDialog.Builder(context) .setTitle("Contentful Error") .setMessage("Could not create an environment." + "\n\nReason: " + exception.toString()) .show(); super.onFailure(exception); } } ); ``` ```java Java // Create the Contentful client. final CMAClient client = new CMAClient .Builder() .setAccessToken("") .setSpaceId("") .setEnvironmentId("") .build(); final CMAEnvironment environment = new CMAEnvironment() .setName("name " + Math.random()); client .environments() .create("", environment); ``` ```kotlin Kotlin // Create the Contentful client. val client = CMAClient.Builder() .setAccessToken("") .setSpaceId("") .setEnvironmentId("") .build() val environment = CMAEnvironment() .setName("name " + Math.random()) client .environments() .create("", environment) ``` ```swift Swift We currently don't provide a CMA SDK for this platform. ``` ```js-legacy JavaScript (legacy) import { createClient } from 'contentful-management' const client = createClient({ accessToken: '' }, { type: 'legacy' }) client.getSpace('') .then((space) => space.createEnvironment({name: 'myEnv'})) .then((environment) => console.log(environment)) .catch(console.error) ``` ```javascript JavaScript import { createClient } from 'contentful-management' // Client init const client = contentful.createClient({ accessToken: '' }) const environment = await client.environment.create( { spaceId: '', }, { name: 'Staging', } ); ``` ```php PHP $client = new \Contentful\Management\Client(''); $space = $client->getSpaceProxy(''); $environment = new \Contentful\Management\Resource\Environment(''); $space->create($environment); ``` ```ruby Ruby require 'contentful/management' client = Contentful::Management::Client.new('') environment = client.environments('').create(name: 'New Environment') ``` ```python Python from contentful_management import Client client = Client('') environment = client.environments('').create( None, { 'name': 'New Environment' } ) ``` ```.net .NET // This client should only be created once per application. var httpClient = new HttpClient(); var client = new ContentfulManagementClient(httpClient, "", ""); var environment = await client.CreateOrUpdateEnvironment("", ""); ```