Prompt
How do I forward calls from one number to another with an API?
Latest observation
To forward calls from one number to another using an API, you usually need a telephony provider that controls the phone number and supports either:
- Call forwarding configuration on the number itself, or
- Programmable call handling where inbound calls are answered by your app and then dialed onward to another number.
Common approaches
1) Direct forwarding on the provider
Some providers let you set a destination number for an inbound phone number via API.
Typical flow:
- Buy or port a phone number
- Update that number’s voice settings
- Set the inbound route to forward to another number
Example conceptually:
- Incoming call to
+15551234567 - Provider automatically forwards it to
+15557654321
This is simplest if your provider supports it.
2) App-controlled forwarding
If the provider doesn’t offer direct forwarding, or you want logic-based routing, you:
- Configure the number to send inbound calls to a webhook
- Your app receives the call event
- Your app responds with instructions to connect the call to the destination number
This lets you add rules like:
- Forward only during business hours
- Forward based on caller ID
- Ring multiple numbers
- Send voicemail if no one answers
Example with Twilio
If you use Twilio, you can forward an inbound call by returning TwiML from your webhook:
<Response>
<Dial>+15557654321</Dial>
</Response>
If you want to configure a Twilio number via API to hit your webhook, you update the number’s voice URL.
Python example
from twilio.rest import Client
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token = "your_auth_token"
client = Client(account_sid, auth_token)
incoming_number = client.incoming_phone_numbers.list(phone_number="+15551234567")[0]
incoming_number.update(voice_url="https://yourapp.com/forward-call")
Then your webhook returns:
from flask import Flask, Response
app = Flask(__name__)
@app.route("/forward-call", methods=["POST"])
def forward_call():
twiml = """
<Response>
<Dial>+15557654321</Dial>
</Response>
"""
return Response(twiml, mimetype="text/xml")
Example with Vonage/Nexmo
You’d typically point the number to an inbound webhook, then respond with NCCO instructions:
[
{
"action": "connect",
"from": "YOUR_VONAGE_NUMBER",
"endpoint": [
{
"type": "phone",
"number": "+15557654321"
}
]
}
]
Things to keep in mind
- Consent and legality: Call forwarding can be regulated in some regions.
- Caller ID: Decide whether to preserve original caller ID.
- Costs: You may be billed for both inbound and outbound legs.
- Availability: Ensure the destination number can receive forwarded calls.
- Emergency services: Forwarding typically should not be used for emergency numbers.
If you want the simplest answer
Use your telephony provider’s API to:
- Point the inbound number to a webhook or forwarding destination
- In that webhook, instruct the provider to connect the call to the target number
If you tell me which provider you’re using (Twilio, Vonage, Plivo, Telnyx, etc.), I can give you the exact API calls and code.