I can't find how to set up or change the Webhook through API. Is it possible to change it, set it when I am buying a number, or select one Webhook URL for all numbers?
I tried to find this info in the documentation but there was helpful to me
I can't find how to set up or change the Webhook through API. Is it possible to change it, set it when I am buying a number, or select one Webhook URL for all numbers?
I tried to find this info in the documentation but there was helpful to me
Yes, you can do that with the following command from the CLI:
twilio phone-numbers:update <TWILIO_NUMBER> --voice-url https://xxxxxxxx.ngrok.io --sms-url https://xxxxxxxx.ngrok.io
or with Node
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
const client = require('twilio')(accountSid, authToken);
client.incomingPhoneNumbers('PNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
.update({voiceUrl: 'https://www.your-new-voice-url.com/example'})
.then(incoming_phone_number => console.log(incoming_phone_number.friendlyName));
You can find other snippets in the docs (scroll to "Example 2 Update IncomingPhoneNumber to use a new Voice URL").
PS: If you want to reuse the same configuration for multiple phone numbers, you might want to see whether TwiML Apps can help you too.
You will have to log into your Twilio console.
From the Develop tab, select Phone Numbers, then Manage > Active Numbers.
You can set the default Webhook (and back-up alternate Webhook) by clicking on the desired number and entering it under the respective Phone or (if available) SMS fields. You will likely have to set the Webhook (takes 2 seconds) for each phone number purchased as the default is the Twilio Demo URL (replies back with Hi or something)
The nature of a Webhook should allow any change in functionality to be done externally (on your end) through your Webhook script's functionality and thus dynamically changing the Webhook URL through the API on a case-by-case basis is discouraged and frankly should not be necessary. Someone may correct me if mistaken.