Search code examples
phptwiliosid

Subaccount SID & Token Retrieval


I currently am developing a PHP application for a large amount of users using the Twilio API.

I was successful in allowing users to login and create a subaccount, but what I found I need to do in order for them to be able to individually purchase their own numbers is dynamically pull each subaccount SID & Access token based on whatever account is currently logged in (or so I think this is the way of going about it).

From what I can see in the API documentation, it doesn't seem like there's a straightforward way of doing this.

Can anyone offer any guidance?


Solution

  • Twilio developer evangelist here.

    I would recommend that when you sign up a user and create a subaccount for them that you save the subaccount's SID and auth token to a local database of yours. Then, when a user tries to buy a phone number you can pull their credentials from the database, initialise a REST client using the helper library using the credentials and make calls to the API on behalf of the subaccount.

    Does that help at all?