Skip to navigation

tokens.create

Create a new API token for the project.

Request

namestringRequired
The name representing the API token.
permissionslist of enumsRequired
The permissions you would like to enable for this token. Valid permissions are calling, chat, datasphere, fax, management, messaging, numbers, pubsub, storage, tasking, and video
project_idstringOptionalformat: "uuid"
Personal access token only. The project to create the token for. Required with a Personal access token and must name a project the token holder can reach (`invalid_project_id`). Ignored with a project API token, which creates the token on its own project.
subproject_idstringOptionalformat: "uuid"
The unique identifier of the subproject you would like to create a token for. The subproject passed must be a child of the project used to authenticate the request, or of `project_id` when authenticating with a Personal access token.

Response

idstringRequiredformat: "uuid"
The ID of the API Token.
namestring or nullRequired
The name of the API Token. `null` when the token has no name.
permissionslist of enumsRequired
The permissions enabled for this token.
last_used_atdatetime or nullRequired
The date and time the token last authenticated a request. `null` if it never has.
revoked_atdatetime or nullRequired
The date and time SignalWire revoked the token's value, for example after detecting that the value was exposed. `null` if it has not been revoked. A revoked token keeps its `id` and still appears in [List API tokens](/docs/apis/rest/project-tokens/list-tokens), but its previous value no longer authenticates and no replacement value has been issued to you. To get a working value, [regenerate the token](/docs/apis/rest/project-tokens/regenerate-token), which also clears `revoked_at`.
tokenstringRequired
The API token that can be used along with the project ID for basic authentication. It is returned only when the token is created or regenerated and cannot be retrieved again; store it securely.

Response Example

Response
{
"id": "ea14556a-984f-11ee-b9d1-0242ac120002",
"name": "John Doe's Token",
"permissions": [
"calling",
"fax",
"messaging"
],
"last_used_at": "2024-05-06T12:20:00Z",
"revoked_at": null,
"token": "swapi_0123456789ab0123456789ab0123456789ab"
}

Example

import { RestClient } from "@signalwire/sdk";
const client = new RestClient({
project: "your-project-id",
token: "your-api-token",
host: "your-space.signalwire.com"
});
const token = await client.project.tokens.create({ name: "ci-token" });
console.log("Token:", token["token"]);
console.log("ID:", token.id);