How to transfer phone number from master account to subaccount
Asked Answered
T

3

7

I have read the tutorial in twilio but its not quite clear.

Can someone lay down the step by step procedure please?

Here is what I got from twilio:

Exchanging Phone Numbers Between Accounts

You can transfer numbers between subaccounts, and between your master account and any one of your subaccounts. You must use your master account's credentials when making the API request to transfer a phone number.

To transfer a phone number between two accounts that you control, make an HTTP POST request to an IncomingPhoneNumber instance resource URI. In the body of the POST set the parameter 'AccountSid' to the AccountSid of the account you wish to own that number. This will remove the phone number from its original account and make it available under the IncomingPhoneNumbers list resource of the new account while retaining all other properties.

Remember, closing a subaccount as described above will release all of that account's phone numbers, so you might consider transferring all numbers to your master account beforehand if you want to keep them.

Tybi answered 12/10, 2014 at 16:15 Comment(2)
Twilio evangelist here. What programming language are you using?Telekinesis
Hi Devin, I am using phpTybi
C
8

One line with curl https://curl.haxx.se/.

You will need to know:

  • from the account where the phone number currently is

    SOURCE-ACCOUNT-SID

    PHONE-NUMBER-SID

  • from the account where the phone number will be transfered

    DESTINATION-ACCOUNT-SID

  • from your master Twilio account

    MASTER-ACCOUNT-SID

    MASTER-ACCOUNT-TOKEN

Here is the command:

curl -XPOST https://api.twilio.com/2010-04-01/Accounts/SOURCE-ACCOUNT-SID/IncomingPhoneNumbers/PHONE-NUMBER-SID.json -d "AccountSid=DESTINATION-ACCOUNT-SID" -u "MASTER-ACCOUNT-SID:MASTER-ACCOUNT-TOKEN"

.

Note: when you replace the values it looks something like this

curl -XPOST https://api.twilio.com/2010-04-01/Accounts/AC0123456789abcdefabcdefabcdefabcd/IncomingPhoneNumbers/PN0123456789abcdefabcdefabcdefabcd.json -d "AccountSid=AC0123456789abcdefabcdefabcdefabcd" -u "AC0123456789abcdefabcdefabcdefabcd:0123456789abcdefabcdefabcdefabcd"

Chlorite answered 18/6, 2016 at 20:33 Comment(1)
Somehow using your example worked even when following the documentation on the Twilio website (which is different!) didn't. Thanks!Chian
T
5

Twilio evangelist here.

To transfer a phone number from a master account to a subaccount, you'll make a POST request to the IncomingPhoneNumber resource that you want to transfer, setting the AccountSid of that resource to the Subaccount SID that you want to move the account into. Using the PHP helper it looks like this:

//Create a new instance of the helper library using master accounts credentials
$client = new Services_Twilio($sid, $token);

// Get the phone number that you want to transfer
$number = $client->account->incoming_phone_numbers->get("PN2a0747eba6abf96b7e3c3ff0b4530f6e");

// update the phone number resources with the account sid of the subaccount
$number->update(array(
    "AccountSid" => "ACecb5a0741d3b8570bcb094ea4dd471d4"
));

Hope that helps.

Telekinesis answered 13/10, 2014 at 18:3 Comment(0)
D
0

You can do this easily in Python:

from twilio.rest import TwilioRestClient
client = TwilioRestClient(MASTER_ACCOUNT_SID, MASTER_AUTH_TOKEN)
account = client.accounts.get(MASTER_ACCOUNT_SID)
number = account.incoming_phone_numbers.get(NUMBER_SID)
number.update(account_sid=SUBACCOUNT_SID)

Make sure to install twilio's Python package if you haven't already:

pip install twilio
Damalus answered 18/6, 2016 at 12:12 Comment(1)
This answer is now outdated. from twilio.rest import Client client = Client(MASTER_ACCOUNT_SID, MASTER_AUTH_TOKEN) account = client.accounts.get(MASTER_ACCOUNT_SID) number = account.incoming_phone_numbers.get(NUMBER_SID) number.update(account_sid=SUBACCOUNT_SID) Seems to work now though.Sisely

© 2022 - 2024 — McMap. All rights reserved.