Environments

$envless->environments->duplicate()

Copy an environment and its variables

php
/** @return EnvironmentResource */
public function duplicate(
    string $project,
    string $environment,
    ?string $product = null,
    int|float|null $timeout = null,
): array

Copies an environment and all of its variables, ciphertext included, into the same project in one transaction. There is no request body. Version history is not copied, so the clone starts with nothing published.

The copy is named <name> (Copy), truncated to 50 characters, and its slug comes from that name with a -2, -3 suffix until one is free, falling back to a random six-character suffix after enough collisions. Never guess the resulting slug, read it off the returned resource. The per-project allowance is checked before any copying starts, so a 402 or a 409 leaves nothing half-created.

Example

php
use Envless\Envless;

$envless = new Envless();

$copy = $envless->environments->duplicate('api', 'production');

echo $copy['slug'], PHP_EOL;

Parameters

ParameterTypeRequiredDescription
$projectstringYesProject slug or uniqueId that owns the source environment.
$environmentstringYesSlug of the environment to copy; ids are not accepted.
$productstringNoProduct slug that disambiguates an ambiguous project slug.
$timeoutint|floatNoSeconds each attempt of this call may take, the response body included, before it throws Envless\Exception\NetworkException with isTimeout() true. Overrides the client's timeout for this call, and 0 turns the limit off.

Returns

EnvironmentResource for the new copy, including its generated slug.

Worth knowing

  • The key needs both environments:write and variables:write, since variables move with the environment.
  • Values are copied as stored ciphertext, so the copy decrypts with the same passphrase as the source.
  • exposed is false on the copy whatever the source was set to.

Required scopes

environments:write and variables:write

Underlying endpoint

POST /projects/{slug}/environments/{environmentSlug}/duplicate

Request and response schema, every error code, and a live playground.

In TypeScript

envless.environments.duplicate()

The same method in @goenvless/sdk, with the same request, retries and errors.