REST Client

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.phone_numbers on a RestClient instance.

1from signalwire.rest import RestClient
2
3client = RestClient(
4 project="your-project-id",
5 token="your-api-token",
6 host="your-space.signalwire.com",
7)
8
9available = client.phone_numbers.search(area_code="512")
10for number in available.get("data", []):
11 print(number["phone_number"])

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 keyword arguments through to update for fields the helper doesn’t name explicitly. Setting a binding auto-materializes the matching Fabric resource on the server.

PhoneCallHandler enum

For callers passing call_handler directly to update, the PhoneCallHandler enum provides typed values. Each member is a str subclass, so passing the enum member serializes to the wire value without .value indirection.

1from signalwire.rest import PhoneCallHandler
2
3client.phone_numbers.update(
4 "phone-number-id",
5 call_handler=PhoneCallHandler.AI_AGENT,
6 call_ai_agent_id="ai-agent-id",
7)
Enum 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 set_swml_webhook helper.