> 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 with a specified ID

PUT https://api.contentful.com/spaces/{space_id}/environments/{environment_id}
Content-Type: application/vnd.contentful.management.v1+json

Creates a new environment with the specified ID, or clones from a source environment via `X-Contentful-Source-Environment`. When updating an existing environment, include the current version in `X-Contentful-Version`.

Reference: https://contentful.com/developers/docs/references/content-management-api/environments/create-an-environment-with-a-specified-id

## 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 the form of a string
- `environment_id` (string, required) — ID of the environment in form of a string

### Headers

- `X-Contentful-Source-Environment` (string, optional) — Environment ID for the desired source environment
- `X-Contentful-Version` (string, optional) — Version of the environment to update

### 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-01-16T03:04:22.000Z",
    "createdBy": {
      "sys": {
        "id": "7BslKh9TdKGOK41VmLDjFZ",
        "linkType": "User",
        "type": "Link"
      }
    },
    "id": "staging",
    "space": {
      "sys": {
        "id": "yadj1kx9rmg0",
        "linkType": "Space",
        "type": "Link"
      }
    },
    "type": "Environment",
    "updatedAt": "2025-01-16T03:04:22.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();

CMAEnvironment environment = new CMAEnvironment().setName("new_environment").setId("new_id");
  client
  .environments()
  .async()
  .create(environment,
      new CMACallback < CMAEnvironment > () {
        @Override protected void onSuccess(CMAEnvironment environment) {
          // Successfully created the environment.
        }
        @Override protected void onFailure(RuntimeException exception) {
          // An error occurred!
          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();

CMAEnvironment created = null;
try {
    CMAEnvironment environment = new CMAEnvironment().setName("new_environment").setId("new_id");
    created = client.environments().create(environment);
    while (created.getStatus() != CMAEnvironmentStatus.Ready) {
        created = client.environments().fetchOne(created.getId());
    }
} catch (Exception e) {
  e.printStackTrace();
}
```

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

var created: CMAEnvironment? = null
  try {
    val environment = CMAEnvironment().setName("new_environment").setId("new_id")
    created = client.environments().create(environment)
    while (created!!.status != CMAEnvironmentStatus.Ready) {
      created = client.environments().fetchOne(created.id)
  }
```

```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.createEnvironmentWithId('<environment_id>', {name: "Staging"}))
  .then((environment) => console.log(`Environment ${environment.sys.id} created.`))
  .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.createWithId(
  {
    spaceId: '<space_id>',
    environmentId: '<custom_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, '<environment_id>');
```

```ruby Ruby
require 'contentful/management'

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

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

```python Python
from contentful_management import Client

client = Client('<content_management_api_key>')

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