REST Client

TypeScript API reference for RestClient and resource namespaces
View as MarkdownOpen in Claude

The REST namespace provides an HTTP client for the SignalWire platform APIs. It organizes every HTTP endpoint into namespaced resource objects with standard CRUD operations, letting you manage phone numbers, fabric resources, call logs, video rooms, datasphere documents, and more from TypeScript.

Example

Search for available phone numbers, purchase one, and assign it to a fabric AI agent resource:

1import { RestClient } from "@signalwire/sdk";
2
3const client = new RestClient({
4 project: "your-project-id",
5 token: "your-api-token",
6 host: "your-space.signalwire.com"
7});
8
9// Search for available numbers in area code 512
10const available = await client.phoneNumbers.search({ areaCode: "512", quantity: 3 });
11for (const number of available.data ?? []) {
12 console.log(`${number.number} - ${number.region}`);
13}
14
15// Purchase the first available number
16const purchased = await client.phoneNumbers.create({ number: available.data[0].number });
17console.log(`Purchased: ${purchased.number}`);
18
19// List your AI agent resources
20const response = await client.fabric.aiAgents.list();
21for (const agent of response.data ?? []) {
22 console.log(`Agent: ${agent.name} (${agent.id})`);
23}
24
25// Query recent voice call logs
26const logs = await client.logs.voice.list({ pageSize: 5 });
27for (const log of logs.data ?? []) {
28 console.log(`Call from ${log.from} to ${log.to}`);
29}

All three constructor arguments can also be provided via environment variables: SIGNALWIRE_PROJECT_ID, SIGNALWIRE_API_TOKEN, and SIGNALWIRE_SPACE. When those are set, you can instantiate with new RestClient() and no arguments.

Error Handling

REST errors throw RestError:

1import { RestClient, RestError } from "@signalwire/sdk";
2
3const client = new RestClient();
4
5try {
6 await client.phoneNumbers.get("nonexistent-id");
7} catch (e) {
8 if (e instanceof RestError) {
9 console.log(`HTTP ${e.statusCode}: ${e.body}`);
10 console.log(`URL: ${e.method} ${e.url}`);
11 }
12}

Resources