---
search:
  tags:
    - Environments
    - POST
seo:
  description: >-
    Creates an environment in a project, empty or as a copy of… Reference for
    the POST /_luna/orgs/{org}/projects/{project}/environments endpoint in the
    Luna API.
sidebar:
  label: Create an environment
  badge: POST
title: Create an environment
type: openapi-operation
---
Creates an environment in a project, empty or as a copy of another. A copy takes the code of `from`, and its data when `data` is set, which also needs `data:read` on the source. Secrets are never copied.

`POST /_luna/orgs/{org}/projects/{project}/environments`

**Request body** (`application/json`, required)

- `name` (string, required) — Lower-case letters, digits and single dashes. \`production\` is taken.
- `from` (string | null) — An environment to copy the code from, by its name or its id. Leave it out for an empty environment.
- `expiresIn` (integer<int64> | null) — Seconds from now until the environment is deleted. Leave it out for one that stays.
- `data` (boolean) — With \`from\`, copies the data of its lunas as well as its code.

Request body example:

```json
{
  "name": "string",
  "from": "string",
  "expiresIn": 0,
  "data": true
}
```

**Responses**

- `200` — The new environment.
- `default` — The request failed. The status says how and \`error.message\` says why.

Response example, 200:

```json
{
  "id": "string",
  "name": "string",
  "tenant": "string",
  "createdMs": 0,
  "createdBy": "string",
  "expiresMs": 0,
  "from": "string",
  "copy": {
    "from": "string",
    "state": "string",
    "atMs": 0,
    "total": 0,
    "done": 0,
    "copied": 0,
    "skipped": 0,
    "error": "string",
    "startedMs": 0,
    "finishedMs": 0
  },
  "version": 0
}
```
