Which method guarantees zero downtime when migrating a Twilio number to a new application?
0 reputation · 19 Jul 2022, 22:55 UTC
0 reputation · 19 Jul 2022, 22:55 UTC
Move a small Twilio-based telephony application from its current deployment to a new codebase while keeping the same phone number and avoiding any service interruption.
Twilio phone numbers are bound to the Account SID that owns them; transferring the number to another Twilio account requires a support‑initiated request and can take several days. Incoming call and SMS routing is controlled by the Voice URL and SMS URL configured on the number (or via a Messaging Service). Updating these webhooks is instant but not transactional, so a mis‑configured endpoint can cause immediate failures.
Should the migration keep the existing Twilio account and simply swap the webhook endpoints, or is it preferable to transfer the number to a new account and then re‑configure the routing? The choice depends on the expected support turnaround, regulatory requirements, and the ability to run parallel instances of the old and new application.
31775 reputation · 20 Jul 2022, 10:27 UTC
The method that guarantees zero downtime when moving a Twilio number to a new application is the Twilio Number Migration API. It is an asynchronous, account‑internal operation that keeps the number reachable while the old application remains active until the migration status turns Completed.
# Twilio CLI example – replace {APPLICATION_SID} with the new app’s SID
$ twilio api:core:applications:assignments:create \
--application {APPLICATION_SID} \
--phone-number +1234567890
Or use the REST API:
POST https://api.twilio.com/2010-04-01/Accounts/{AccountSid}/Applications/{NewApplicationSid}/Assignments.json
Content-Type: application/x-www-form-urlencoded
Body: PhoneNumber=%2B1234567890
status field reads Completed.
After migration, the Voice URL will still point to the new application, but any Studio Flow or Flex configuration that referenced the old application will need to be updated manually. Re‑link the flow or worker pool to the new application’s SID to maintain full functionality.
To ensure the recommendation fits your exact setup, could you confirm whether the phone number is currently linked to a Twilio Studio Flow or Flex worker pool? If so, we’ll outline the exact re‑association steps after migration.
Use comments to ask for clarification. Post a solution as an answer.
31,775 reputation · 20 Jul 2022, 03:35 UTC
The Applications/{ApplicationSid}/Assignments endpoint only re‑assigns a phone number to a different application *within the same Twilio account*. It does not transfer the number between accounts, nor does it guarantee that inbound traffic will never be lost during the switch.
Updating a number’s Voice URL and Messaging URL in separate API calls creates a brief window where one endpoint is live and the other is still pointing at the old application. Calls or SMS that arrive during that window can be routed to the wrong code path. Twilio’s PhoneNumbers API lets you supply both URLs in the same request, making the change atomic from Twilio’s perspective.
POST https://api.twilio.com/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{PhoneNumberSid}.json
Content-Type: application/x-www-form-urlencoded
Body: VoiceUrl=https://new.app/call&MessagingUrl=https://new.app/sms
Configure a TwiML Bin or a Studio Flow as a fallback. If the new webhook is unreachable, Twilio will fall back to the TwiML Bin, ensuring that calls or SMS are still answered with a graceful message while you investigate the issue.