/**
* @param EnvironmentCreate $body
* @return EnvironmentResource
*/
public function create(
string $project,
array $body,
?string $product = null,
int|float|null $timeout = null,
): arrayCreates 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
use Envless\Envless;
$envless = new Envless();
$environment = $envless->environments->create('api', [
'name' => 'Production',
'slug' => 'production',
]);
echo "{$environment['id']} {$environment['slug']}", PHP_EOL;Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
$project | string | Yes | Project slug or uniqueId that will own the environment. |
$body | EnvironmentCreate | Yes | The fields below, as one array. |
$body['name'] | string | Yes | Display name, 2 to 50 characters. |
$body['slug'] | string | Yes | Lowercase hyphenated slug, unique inside the project. |
$product | string | No | Product slug that disambiguates an ambiguous project slug. |
$timeout | int|float | No | Seconds 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
exposedis always false here; publishing a feed is a separateexposecall.- On a 402 the error
resourcenames the allowance that was hit and itsmessagestates the limit. The response body also carrieslimitandcurrent, whichEnvless\Exception\ApiExceptiondoes 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.