Products

$envless->products->duplicate()

Clone a product with its projects and variables

php
/** @return ProductResource */
public function duplicate(
    string $slug,
    int|float|null $timeout = null,
): array

Clones a product together with every project, environment and variable underneath it. Ciphertext is copied verbatim, so the clone decrypts with the same workspace passphrase and needs no re-encryption pass.

The name and slug of the clone are derived from the source and are not predictable, so read them off the response rather than guessing at a suffix. Version history is not carried over, so the cloned environments start with no versions.

A key restricted to specific projects is refused outright, because the clone creates project ids outside that allowlist. Both the product cap and the project cap of the plan are enforced, and either one being full fails the call.

Example

php
use Envless\Envless;

$envless = new Envless();

$clone = $envless->products->duplicate('billing');
$projects = $envless->products->listAllProjects($clone['slug']);

echo $clone['slug'], ' ', count($projects), PHP_EOL;

Parameters

ParameterTypeRequiredDescription
$slugstringYesSlug or uniqueId of the product to copy.
$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

ProductResource for the clone, including the generated name and slug.

Worth knowing

  • Duplicating a private product keeps the privacy flag and copies the grants recorded on the source.
  • The whole copy runs in one transaction, so a failed call leaves no half-built product behind.

Required scopes

products:write and projects:write and variables:write

Underlying endpoint

POST /products/{slug}/duplicate

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

In TypeScript

envless.products.duplicate()

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