--- name: inbound-sip-routing title: "Inbound SIP Routing" description: "Route inbound SIP calls to your endpoints." language: python framework: flask telnyx_products: [] --- # Flask application for managing inbound SIP routing with Telnyx. Application. Built with Telnyx Migration, Number Porting. ## Telnyx API Endpoints Used - **Create SIP Connection**: `POST /v2/sip_connections` — [API reference](https://developers.telnyx.com/api/sip-connections/create-sip-connection) - **List SIP Connections**: `GET /v2/sip_connections` — [API reference](https://developers.telnyx.com/api/sip-connections/list-sip-connections) - **Retrieve SIP Connection**: `GET /v2/sip_connections/{id}` — [API reference](https://developers.telnyx.com/api/sip-connections/get-sip-connection) ## Architecture ``` Your PBX / SBC │ ▼ ┌──────────────────┐ │ Telnyx SIP Trunk │ │ (IP / FQDN auth) │ └────────┬─────────┘ │ ▼ PSTN / Telnyx Network ``` ## Environment Variables Copy `.env.example` to `.env` and fill in: | Variable | Type | Example | Required | Description | Where to get it | |----------|------|---------|----------|-------------|-----------------| | `TELNYX_API_KEY` | `string` | `KEY0123456789ABCDEF` | **yes** | Telnyx API v2 key | [Portal](https://portal.telnyx.com/api-keys) | | `FLASK_DEBUG` | `string` | `false` | no | Flask debug | — | ## Setup ```bash git clone https://github.com/team-telnyx/telnyx-code-examples.git cd telnyx-code-examples/inbound-sip-routing-python cp .env.example .env # ← fill in your credentials pip install -r requirements.txt python app.py # starts on http://localhost:5000 ``` ## API Reference ### `GET /sip/connections` List all SIP connections configured for inbound routing. ```bash curl http://localhost:5000/sip/connections ``` **Response:** ```json { "connections": [ { "id": "1494404757140276705", "name": "Production SIP", "status": "active", "ip": "192.168.1.100" } ] } ``` ### `POST /sip/connections` Create a new SIP connection for inbound call routing. ```bash curl -X POST http://localhost:5000/sip/connections \ -H "Content-Type: application/json" \ -d '{}' ``` **Response:** ```json { "connections": [ { "id": "1494404757140276705", "name": "Production SIP", "status": "active", "ip": "192.168.1.100" } ] } ``` ### `GET /sip/connections/` Get detailed information about a specific SIP connection. ```bash curl http://localhost:5000/sip/connections/example-id ``` **Response:** ```json { "connections": [ { "id": "1494404757140276705", "name": "Production SIP", "status": "active", "ip": "192.168.1.100" } ] } ``` ## Troubleshooting | Issue | Cause | Fix | |-------|-------|-----| | `401 Unauthorized` | Invalid or missing API key | Verify `TELNYX_API_KEY` in `.env` matches your key in the [Portal](https://portal.telnyx.com/api-keys) | | Webhook not received | Local server not publicly reachable | Expose it with a tunnel (e.g. ngrok) and set the webhook URL in the [Telnyx Portal](https://portal.telnyx.com) | | `422 Unprocessable Entity` | Missing or malformed request fields | Check the request body against the API Reference above | ## Related Examples - [Configure SIP Codecs (Python)](https://raw.githubusercontent.com/team-telnyx/telnyx-code-examples/main/configure-sip-codecs-python/README.md) - [Setup SIP Trunk (Python)](https://raw.githubusercontent.com/team-telnyx/telnyx-code-examples/main/setup-sip-trunk-python/README.md) - [SIP Failover Routing (Python)](https://raw.githubusercontent.com/team-telnyx/telnyx-code-examples/main/sip-failover-routing-python/README.md) - [SIP Load Balancer Health Check (Python)](https://raw.githubusercontent.com/team-telnyx/telnyx-code-examples/main/sip-load-balancer-health-check-python/README.md) - [SIP Trunking Failover Monitor (Python)](https://raw.githubusercontent.com/team-telnyx/telnyx-code-examples/main/sip-trunking-failover-monitor-python/README.md) ## Resources - [Telnyx Developer Docs](https://developers.telnyx.com) - [Telnyx Portal](https://portal.telnyx.com) ## Why Telnyx Telnyx is an **AI Communications Infrastructure** platform — voice, messaging, SIP, AI, and IoT on one private, global network.