Skip to navigation

Phone Numbers

View as MarkdownOpen in Claude

Search for available phone numbers, purchase them, and manage the numbers in your SignalWire project. This resource extends the standard CRUD pattern with a search() method for discovering available numbers, uses PUT for updates, and provides typed helpers for binding inbound calls to a handler (SWML webhook, cXML webhook, AI agent, call flow, Relay application/topic).

Access via client.phoneNumbers on a RestClient instance.

Idiomatic deviation: create() and update() accept an untyped body object (Record<string, unknown>) rather than narrow per-field types. This mirrors Python’s **kwargs-style flexibility. Response payloads follow the same typing.

import { RestClient } from "@signalwire/sdk";
const client = new RestClient({
project: "your-project-id",
token: "your-api-token",
host: "your-space.signalwire.com"
});
const available = await client.phoneNumbers.search({ areacode: "512" });
for (const number of available.data ?? []) {
console.log(number.phoneNumber);
}

Methods

Standard CRUD

Typed Binding Helpers

Each helper is a one-line wrapper over update that sets call_handler to the right value and populates the handler-specific companion field for you. Pass extra wire-level fields through the extra argument (or as additional keys on the params object) for fields the helper doesn’t name explicitly. Setting a binding auto-materializes the matching Fabric resource on the server.

PhoneCallHandler

For callers passing call_handler directly to update, the PhoneCallHandler const provides typed values. It is a const-as-enum (as const object plus a same-named string-union type), so passing a member serializes to its wire value with full type-checking on the call site.

import { PhoneCallHandler } from "@signalwire/sdk";
await client.phoneNumbers.update("phone-number-id", {
call_handler: PhoneCallHandler.AI_AGENT,
call_ai_agent_id: "ai-agent-id",
});
MemberWire valueCompanion fieldAuto-creates
RELAY_SCRIPTrelay_scriptcall_relay_script_urlswml_webhook
LAML_WEBHOOKSlaml_webhookscall_request_urlcxml_webhook
LAML_APPLICATIONlaml_applicationcall_laml_application_idcxml_application
AI_AGENTai_agentcall_ai_agent_idai_agent
CALL_FLOWcall_flowcall_flow_idcall_flow
RELAY_APPLICATIONrelay_applicationcall_relay_applicationrelay_application
RELAY_TOPICrelay_topiccall_relay_topic(routes via Relay)

LAML_WEBHOOKS (wire value laml_webhooks) produces a cXML handler, not a generic webhook. For SWML, use RELAY_SCRIPT — or, more conveniently, the setSwmlWebhook helper.