> 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/developers/docs/_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 <token>`, 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("<access_token>")
        .setSpaceId("<space_id>")
        .setEnvironmentId("<environment_id>")
        .build();

// Create a local environment.
final CMAEnvironment environment =
    new CMAEnvironment()
        .setName("name");

// Create the same environment in Contentful.
client
    .environments()
    .async()
    .create(
        "<space_id>",
        environment,
        new CMACallback<CMAEnvironment>() {
          @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("<access_token>")
        .setSpaceId("<space_id>")
        .setEnvironmentId("<environment_id>")
        .build();

final CMAEnvironment environment = new CMAEnvironment()
    .setName("name " + Math.random());

client
    .environments()
    .create("<space_id>", environment);
```

```kotlin Kotlin
// Create the Contentful client.
val client = CMAClient.Builder()
    .setAccessToken("<access_token>")
    .setSpaceId("<space_id>")
    .setEnvironmentId("<environment_id>")
    .build()

val environment = CMAEnvironment()
    .setName("name " + Math.random())

client
    .environments()
    .create("<space_id>", 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: '<content_management_api_key>'
}, { type: 'legacy' })

client.getSpace('<space_id>')
  .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: '<content_management_api_key>'
})

const environment = await client.environment.create(
  {
    spaceId: '<space_id>',
  },
  {
    name: 'Staging',
  }
);
```

```php PHP
$client = new \Contentful\Management\Client('<content_management_api_key>');

$space = $client->getSpaceProxy('<space_id>');

$environment = new \Contentful\Management\Resource\Environment('<environment_name>');

$space->create($environment);
```

```ruby Ruby
require 'contentful/management'

client = Contentful::Management::Client.new('<content_management_api_key>')

environment = client.environments('<space_id>').create(name: 'New Environment')
```

```python Python
from contentful_management import Client

client = Client('<content_management_api_key>')

environment = client.environments('<space_id>').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, "<content_management_api_key>", "<space_id>");

var environment = await client.CreateOrUpdateEnvironment("<environment_id>", "<environment_name>");
```