RestClient

View as MarkdownOpen in Claude

The RestClient is the entry point for all SignalWire REST API operations. It authenticates with your project credentials and exposes every API namespace as a property, giving you typed access to phone numbers, fabric resources, call control, video rooms, datasphere documents, logs, and more.

Constructor parameters

project
string

SignalWire project ID. Falls back to the SIGNALWIRE_PROJECT_ID environment variable when not provided.

token
string

API token for authentication. Falls back to the SIGNALWIRE_API_TOKEN environment variable when not provided.

host
string

SignalWire space hostname (e.g., your-space.signalwire.com) or a full https:// base URL. When not provided, falls back to the SIGNALWIRE_REST_BASE_URL environment variable (a full URL), then to SIGNALWIRE_SPACE (a bare hostname).

requestOptions
RequestOptionsInit

Client-wide default timeout, retry, backoff, and abort settings applied to every request. A per-request requestOptions argument overrides individual fields for that call. See RequestOptions.

fetchImpl
typeof fetch

Custom fetch implementation. Defaults to the global fetch.

project, token, and host are required. If any is missing from both the constructor arguments and environment variables, an Error is thrown.

Namespace properties

fabric
FabricNamespace

AI agents, SWML scripts, subscribers, call flows, SIP gateways, and tokens. See Fabric.

calling
Calling

REST-based call control with 37+ commands dispatched via POST. See Calling.

phoneNumbers
PhoneNumbers

Search, purchase, and manage phone numbers. See Phone Numbers.

addresses
Addresses

Manage regulatory addresses. See Addresses.

queues
Queues

Manage call queues and queue members. See Queues.

recordings
Recordings

List, retrieve, and delete call recordings. See Recordings.

numberGroups
NumberGroups

Manage number groups and their memberships. See Number Groups.

verifiedCallers
VerifiedCallers

Manage and verify caller IDs. See Verified Callers.

sipProfile
SipProfile

Get and update the project SIP profile. See SIP Profile.

lookup
Lookup

Phone number carrier and CNAM lookup. See Lookup.

shortCodes
ShortCodes

Manage short codes. See Short Codes.

importedNumbers
ImportedNumbers

Import externally-hosted phone numbers. See Imported Numbers.

mfa
Mfa

Multi-factor authentication via SMS and voice. See MFA.

registry
RegistryNamespace

10DLC brand and campaign registration. See Registry.

datasphere
DatasphereNamespace

Document management and semantic search. See Datasphere.

video
VideoNamespace

Video rooms, conferences, sessions, recordings, and streams. See Video.

logs
LogsNamespace

Message, voice, fax, and conference log queries. See Logs.

project
ProjectNamespace

API token management for the current project (client.project.tokens). See Project.

pubsub
PubSub

PubSub token generation. See PubSub.

chat
Chat

Chat token generation. See Chat.

messages
Messages

Send SMS and MMS messages and redact message bodies. See Messages.

projects
Projects

Create, update, and delete projects, and rotate a project’s signing key. See Projects.

Examples

Explicit credentials

import { RestClient } from "@signalwire/sdk";
const client = new RestClient({
project: "your-project-id",
token: "your-api-token",
host: "your-space.signalwire.com"
});
const numbers = await client.phoneNumbers.list();

Environment variables

import { RestClient } from "@signalwire/sdk";
// With SIGNALWIRE_PROJECT_ID, SIGNALWIRE_API_TOKEN, and SIGNALWIRE_SPACE set
const client = new RestClient();
const available = await client.phoneNumbers.search({ areacode: "512" });

Factory function

The top-level restClient() factory is a thin wrapper around new RestClient(...). Both forms construct the same client.

restClient(opts?: ClientOptions): RestClient
opts
ClientOptions

The same options the constructor accepts: project, token, host, requestOptions, and fetchImpl. When omitted, the SIGNALWIRE_PROJECT_ID, SIGNALWIRE_API_TOKEN, and SIGNALWIRE_REST_BASE_URL or SIGNALWIRE_SPACE environment variables are read.

import { restClient } from "@signalwire/sdk";
const client = restClient({
project: "your-project-id",
token: "your-api-token",
host: "your-space.signalwire.com",
});
// Or read from environment variables
const envClient = restClient();