Connect a SIP trunk
Summary
This guide connects a workspace SIP setup, configures its connections and trunks, and imports an existing number. It also follows asynchronous operations and shows how to edit or remove the setup. It does not cover agent assignments; see Route phone calls.
Facts
Steps
Set SIP_ENDPOINT to your carrier or PBX host name, without a scheme or path.
Set PHONE_NUMBER to an E.164 number you already own at your carrier.
Use the returned resource_id for CONNECTION_ID after creating an inbound connection, and for TRUNK_ID after creating an outbound trunk.
For an existing setup, read those IDs from inbound_connections and outbound_trunks.
1. Read the setup and its ETag
Set ETAG to the returned ETag, including its quotes.
Refresh ETAG from a mutation response or repeat this read before each later edit.
If enabled is false, SIP trunking is unavailable for the workspace.
A null address has not been created yet.
2. Connect or resume the setup
The 202 response contains setup, resource_id and operation_id.
Acceptance does not mean the asynchronous operation succeeded.
This request is also the retry for a failed setup.
If the setup reports state: failed, read failed_step and failure_reason first, then send the request again with a new Idempotency-Key.
If the same failure_reason comes back, contact support with the X-Request-Id of the retry.
3. Follow setup operations
Each sip.setup event contains a SipTrunkSnapshot: setup, up to 100 recent operations, and revision.
Match operation_id to an operation’s id, then inspect its state.
States include requested, dispatched, running, succeeded, failed and cancelled.
A failed operation has a failure_reason, with the same codes as the setup’s failure_reason.
A bind_number operation that failed with sip_trunk_not_ready ran before the setup was ready: wait for state: ready, then provision the number again.
Keep the last SSE id and send it as Last-Event-ID when reconnecting.
This suppresses an unchanged snapshot; reconnecting returns the latest state rather than a historical event log.
The stream never creates or retries work, and it checks API-key authorization again on every read.
Treat unknown states as unknown rather than success.
4. Create an inbound connection
The answer is 201 with a SipTrunkMutation.
Give your carrier the uri of the entry in the returned setup.addresses whose region matches the connection: the setup’s addresses are the SIP addresses your carrier points at.
A null uri does not exist yet; read the setup again or follow the stream until it has a value.
Use carrier_ips and enforce_carrier_ips to restrict which carrier IP addresses or CIDR ranges can send calls.
5. Create an outbound trunk
The answer is 202. Follow the operation until the trunk is active.
The default port is 5060 and the default transport is udp; set these to the values your carrier requires.
Use kind: pbx for a PBX trunk.
If your carrier requires credentials, supply username and password from your secret manager in the write body.
Neither credential is returned by reads.
6. Import an existing SIP number
The answer is 201. Import does not buy a number.
Continue with Route phone calls to assign a published agent.
7. Edit an inbound connection
Use these maintenance steps when you need to change an existing setup.
Read the current setup and refresh ETAG before each mutation that requires If-Match.
This example restricts inbound calls to an illustrative carrier IP; replace it with your carrier’s documented addresses.
8. Edit an outbound trunk
The answer is 202; follow any returned operation_id on the setup stream.
9. Regenerate the workspace SIP address
The answer is 202. Follow the setup stream and use the resulting address for your carrier configuration.
10. Delete an unused inbound connection
Remove dependencies first if the API refuses deletion with in_use or number_bound.
11. Delete an unused outbound trunk
The answer is 202; follow its operation before treating the trunk as deleted.
12. Disconnect the setup
The answer is 202; inspect the operation’s result on the stream.
Rules
- MUST send the same body and
Idempotency-Keywhen retrying a lost response. - MUST read the current setup and send its ETag on operations that require
If-Match. - MUST inspect the operation state after a
202response. - MUST NOT put carrier credentials in logs or client-side applications.
- MUST NOT treat an unfamiliar stream state as success.
- MUST keep carrier number ownership and routing configuration consistent with your imported numbers.
- MUST wait for
state: readybefore you provision a number on the SIP trunk. - MUST keep an unknown
failure_reasonorfailed_stepvalue, and treat it as a failure.
Verify
After connection succeeds, expect state: ready and the addresses for available regions.
If the setup reports state: failed, failed_step names the step that failed and failure_reason says why.
A setup with state: ready, address_regenerating: true and a failed_step that starts with address_ has a stopped address regeneration, and the old address still routes. Retry it with regenerateSipAddress: connectSipTrunk answers 409 conflict while the setup is ready.
After a maintenance operation, confirm its result in the setup and its terminal state in the stream.