---
title: "Copy Environment Async"
method: POST
path: "/v2/projects/{proj_id}/envs/{env_id}/copy/async"
tags: ["Environments"]
---

# Copy Environment Async

`POST /v2/projects/{proj_id}/envs/{env_id}/copy/async`

Copy environment

This endpoint either duplicates an existing environment to a new environment
in the same project, or copies from an existing environment to another
existing environment.

The `scope` object controls which objects will be copied to the target
environment.

To clone to a new environment, the user must have write permissions
to the containing project. To clone into an existing environment,
the user must have write permissions to the target environment.

Copying environments across projects or organizations is not
allowed.

## Path parameters

- `proj_id` string, required — Either the unique id of the project, or the URL-friendly key of the project (i.e: the "slug").
- `env_id` string, required — Either the unique id of the environment, or the URL-friendly key of the environment (i.e: the "slug").

## Query parameters

- `wait` number — Time in seconds to wait for the task to complete. Default is 0, means no wait.

## Request body

- EnvironmentCopy
  - `target_env` EnvironmentCopyTarget, required
    - `existing` string — Identifier of an existing environment to copy into
    - `new` EnvironmentCreate
      - `key` string, required — A URL-friendly name of the environment (i.e: slug). You will be able to query later using this key instead of the id (UUID) of the environment.
      - `name` string, required — The name of the environment
      - `description` string — an optional longer description of the environment
      - `custom_branch_name` string — when using gitops feature, an optional branch name for the environment
      - `jwks` JwksConfig
        - `ttl` integer — JWKS cache TTL (in seconds)
        - `url` string — ...
        - `jwks` JwksObj
          - `keys` object[], required — The keys to match against the request headers
      - `settings` object — the settings for this environment
  - `conflict_strategy` 'fail' | 'overwrite' — An enumeration.
  - `scope` EnvironmentCopyScope
    - `resources` EnvironmentCopyScopeFilters
      - `include` string[] — Objects to include (use * as wildcard)
      - `exclude` string[] — Object to exclude (use * as wildcard)
    - `roles` EnvironmentCopyScopeFilters
      - `include` string[] — Objects to include (use * as wildcard)
      - `exclude` string[] — Object to exclude (use * as wildcard)
    - `user_sets` EnvironmentCopyScopeFilters
      - `include` string[] — Objects to include (use * as wildcard)
      - `exclude` string[] — Object to exclude (use * as wildcard)
    - `resource_sets` EnvironmentCopyScopeFilters
      - `include` string[] — Objects to include (use * as wildcard)
      - `exclude` string[] — Object to exclude (use * as wildcard)
    - `custom_policies` EnvironmentCopyScopeFilters
      - `include` string[] — Objects to include (use * as wildcard)
      - `exclude` string[] — Object to exclude (use * as wildcard)

## Response `202`

Successful Response

- TaskResultEnvironmentRead
  - `task_id` string, required — The unique id of the task.
  - `status` 'processing' | 'success' | 'failure' | 'cancelled', required — An enumeration.
  - `result` EnvironmentRead
    - `key` string, required — A URL-friendly name of the environment (i.e: slug). You will be able to query later using this key instead of the id (UUID) of the environment.
    - `id` string, uuid, required — Unique id of the environment
    - `organization_id` string, uuid, required — Unique id of the organization that the environment belongs to.
    - `project_id` string, uuid, required — Unique id of the project that the environment belongs to.
    - `created_at` string, date-time, required — Date and time when the environment was created (ISO_8601 format).
    - `updated_at` string, date-time, required — Date and time when the environment was last updated/modified (ISO_8601 format).
    - `avp_policy_store_id` string
    - `name` string, required — The name of the environment
    - `description` string — an optional longer description of the environment
    - `custom_branch_name` string — when using gitops feature, an optional branch name for the environment
    - `jwks` JwksConfig
      - `ttl` integer — JWKS cache TTL (in seconds)
      - `url` string — ...
      - `jwks` JwksObj
        - `keys` object[], required — The keys to match against the request headers
    - `settings` object — the settings for this environment
  - `error` ErrorDetails
    - `id` string, required
    - `title` string, required
    - `support_link` string, uri
    - `error_code` 'INVALID_INPUT' | 'INVALID_JWKS_CONFIGURATION' | 'UNEXPECTED_ERROR' | 'NOT_FOUND' | 'DUPLICATE_ENTITY' | 'EMPTY_DECISION_LOGS' | 'MISSING_REQUEST_ATTRIBUTE' | 'FORBIDDEN_ACCESS' | 'INVALID_PERMISSION_FORMAT' | 'MISSING_PERMISSIONS' | 'UNSUPPORTED_ATTRIBUTE_TYPE' | 'MISSING_RESOURCE_ATTRIBUTE' | 'MISMATCH_ATTRIBUTES_TYPES' | 'INVALID_POLICY_REPO_STATUS' | 'INVALID_SMTP_CONFIGURATION' | 'MISMATCH_RESOURCE_INSTANCES_TENANTS' | 'PAGINATION_SIZE_OVERREACHED' | 'MISMATCH_RELATION_TYPE' | 'CONCURRENT_OPERATION_DISALLOWED' | 'UNAUTHORIZED', required — An enumeration.
    - `message` string
    - `additional_info` unknown

## Other responses

- `422` — Validation Error

---

[API](https://skmtc.dev/permit/apis/permit-io-api.md) · [All operations](https://skmtc.dev/permit/apis/permit-io-api/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/permit/permit-io-api/revisions/13faa12b4692/schema)
