How to transfer a phone number from the main account to the sub-account

I read the tutorial in twilio, but this is not entirely clear.

Can someone add a step-by-step procedure?

Here is what I got from twilio:

Exchange phone numbers between accounts

You can transfer numbers between sub-accounts and between your main account and any of your sub-accounts. You must use the credentials of the master account when the API request is sent to the phone number.

To transfer the phone number between the two accounts you manage, make an HTTP POST request in the resource URI of the IncomingPhoneNumber instance. In the POST body, set the AccountSid parameter to the AccountSID of the account to which you want to belong to this number. This will remove the phone number from its original account and make it available in the IncomingPhoneNumbers resource list of the new account, while retaining all other properties.

Remember that closing a sub-account, as described above, will release all the phone numbers of this account, so you can pre-transfer all numbers to your main account if you want to save them.

+5
source share
3 answers

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

You will need to know:

  • from the account where the phone number is currently

    SOURCE-ACCOUNT-SID

    PHONE-NUMBER-SID

  • from the account to which the phone number will be transferred

    DESTINATION-ACCOUNT-SID

  • from your 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 replacing 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"

+5
source

Twilio the evangelist is here.

To transfer the phone number from the main account to the sub-account, you will make a POST request to the IncomingPhoneNumber resource that you want to transfer by setting the AccountSid of this resource to the SID of the sub-account that you want to transfer to. Using the PHP helper is as follows:

 //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 this helps.

+4
source

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) 

Be sure to install the twilio Python package if you have not already done so:

 pip install twilio 
0
source

Source: https://habr.com/ru/post/1204515/


All Articles