Environments

$envless->environments->create()

Create an environment in a project

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

Creates an environment inside a project. The API requires both name and slug, so always send a slug: it is slugified server-side before validation and has to be free within the project.

The body is parsed and validated before the project is resolved, so a bad name returns 400 even when the project reference is wrong too. The allowance is counted per project, not per workspace the way products and projects are, and it is checked before the slug conflict, so a project that is already at its limit fails with 402 no matter which slug you picked.

Example

php
use Envless\Envless;

$envless = new Envless();

$environment = $envless->environments->create('api', [
    'name' => 'Production',
    'slug' => 'production',
]);

echo "{$environment['id']} {$environment['slug']}", PHP_EOL;

Parameters

ParameterTypeRequiredDescription
$projectstringYesProject slug or uniqueId that will own the environment.
$bodyEnvironmentCreateYesThe fields below, as one array.
$body['name']stringYesDisplay name, 2 to 50 characters.
$body['slug']stringYesLowercase hyphenated slug, unique inside the project.
$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, the full shape that carries exposed and updatedAt.

Worth knowing

  • exposed is always false here; publishing a feed is a separate expose call.
  • On a 402 the error resource names the allowance that was hit and its message states the limit. The response body also carries limit and current, which Envless\Exception\ApiException does not expose.

Required scopes

environments:write

Underlying endpoint

POST /projects/{slug}/environments

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

In TypeScript

envless.environments.create()

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