Projects

$envless->projects->create()

Create a project inside a product

php
/**
 * @param ProjectCreate $body
 * @return ProjectResource
 */
public function create(array $body, int|float|null $timeout = null): array

Creates a project and returns it. The destination product comes from $body['product'], which is a field in the body rather than a query option, and it accepts a product slug only. Omit it and the workspace default product is used, being created on the fly if it does not exist yet.

The API wants both name and slug here, unlike product creation which derives the slug for you. Slug uniqueness is scoped to the chosen product, so the same project slug can exist in several products. The plan allowance is counted across the whole workspace and checked before the slug conflict, so a workspace at its limit fails with 402 even when the slug was also taken.

Example

php
use Envless\Envless;

$envless = new Envless();

$project = $envless->projects->create([
    'name' => 'API',
    'slug' => 'api',
    'product' => 'billing',
]);

echo $project['id'], ' ', $project['product']['slug'] ?? '', PHP_EOL;

Parameters

ParameterTypeRequiredDescription
$bodyProjectCreateYesThe fields below, as one array.
$body['name']stringYesHuman readable project name.
$body['slug']stringYesSlug for the project, slugified before it is validated for uniqueness.
$body['product']stringNoProduct slug to create the project in, defaulting to the workspace default product.
$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

ProjectResource for the newly created project.

Worth knowing

  • slug is required, and a create without it is refused with 400 request.body_invalid.
  • $body['product'] resolves product slugs only. Passing a product uniqueId returns 404 product.not_found.
  • 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

projects:write

Underlying endpoint

POST /projects

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

In TypeScript

envless.projects.create()

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