/**
* @param ProductCreate $body
* @return ProductResource
*/
public function create(array $body, int|float|null $timeout = null): arrayCreates a product in the workspace the key is bound to. Only name is required: an omitted slug is derived from the name, and a supplied slug is slugified before validation, so My Product and my-product both land on my-product.
The response is built from the freshly inserted row, not from a read back. isPrivate is always false, updatedAt is always null and there is no locked field even when the new product went in beyond the plan cap. Call get when you need the settled shape, and update when you need the product to be private.
Example
use Envless\Envless;
$envless = new Envless();
$product = $envless->products->create(['name' => 'Billing']);
echo "{$product['id']} {$product['slug']}", PHP_EOL;Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
$body | ProductCreate | Yes | The fields below, as one array. |
$body['name'] | string | Yes | Display name for the product. |
$body['slug'] | string | No | Preferred slug, slugified before it is validated for uniqueness. |
$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
ProductResource for the new product, with isPrivate false and no locked field.
Worth knowing
- The plan allowance is checked before slug uniqueness, so a workspace at its cap reports the upgrade error even when the slug would also have collided.
- Icons cannot be set here or through
update.
Required scopes
products:write
Underlying endpoint
POST /products
Request and response schema, every error code, and a live playground.
In TypeScript
envless.products.create()
The same method in @goenvless/sdk, with the same request, retries and errors.