Skip to content

Instantly share code, notes, and snippets.

@troyscott
Created January 27, 2013 08:37
Show Gist options
  • Select an option

  • Save troyscott/4647401 to your computer and use it in GitHub Desktop.

Select an option

Save troyscott/4647401 to your computer and use it in GitHub Desktop.
Example of using pycurl to transfer a phone number from a Twilio SubAccount to the Master Account. Couldn't get this to work with the python twilio client.
import pycurl
# http://www.twilio.com/docs/api/rest/subaccounts#exchanging-numbers
def reset_demo(phone_sid):
base = "https://api.twilio.com/2010-04-01/Accounts/"
master_sid = "ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
master_token = "auth token"
subaccount = "ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
login = "%s:%s" % (master_sid, master_token)
data = "AccountSid=%s" % master_sid
uri = "%s%s/IncomingPhoneNumbers/%s" % (base, subaccount,phone_sid)
c = pycurl.Curl()
c.setopt(c.URL,uri)
c.setopt(c.USERPWD, login)
c.setopt(c.POSTFIELDS, data)
c.setopt(c.VERBOSE, True)
c.perform()
phone_list = ["PNxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"PNxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"]
for phone in phone_list:
reset_demo(phone)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment