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.

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
9const available = await client.phoneNumbers.search({ areacode: "512" });
10for (const number of available.data ?? []) {
11 console.log(number.phoneNumber);
12}

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.

1import { PhoneCallHandler } from "@signalwire/sdk";
2
3await client.phoneNumbers.update("phone-number-id", {
4 call_handler: PhoneCallHandler.AI_AGENT,
5 call_ai_agent_id: "ai-agent-id",
6});
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.