/** @return DeletedRoleResource */
public function delete(string $id, int|float|null $timeout = null): arraySoft deletes a custom role and returns a small receipt holding the id and name that were removed. The id is never reused, and the role reads as 404 from then on.
The role has to be unused. Reassign every member holding it with $envless->members->update() and revoke every pending invite that references it with $envless->invites->revoke() first, otherwise the call is refused with 409 role.in_use and the message tells you how many members or invites are in the way. System roles can never be deleted and fail with 409 role.immutable.
Example
use Envless\Envless;
$envless = new Envless();
$role = $envless->roles->listAll(search: 'deploy')[0] ?? null;
if ($role !== null) {
$removed = $envless->roles->delete($role['id']);
echo $removed['name'], PHP_EOL;
}Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
$id | string | Yes | Role id from $envless->roles->list(), which must be a custom role with no members and no pending invites. |
$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
DeletedRoleResource carrying only the id and name of the removed role.
Worth knowing
- The response omits
permissions,descriptionand the timestamps, so read anything you want to keep withgetbefore deleting. - Members are counted before invites, so a role blocked by both reports the member count first and the invite count only after you clear the members.
- Deleting a role emits the
role.deletedwebhook event.
Required scopes
roles:write
Underlying endpoint
DELETE /roles/{id}
Request and response schema, every error code, and a live playground.
In TypeScript
envless.roles.delete()
The same method in @goenvless/sdk, with the same request, retries and errors.