Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I delete a number? #1

Closed
ghost opened this issue Dec 11, 2013 · 4 comments
Closed

How do I delete a number? #1

ghost opened this issue Dec 11, 2013 · 4 comments

Comments

@ghost
Copy link

ghost commented Dec 11, 2013

Hi, using this library, is it possible to delete an existing Twilio number?

@benedmunds
Copy link
Owner

Yes you can, the endpoint is documented here: https://www.twilio.com/docs/api/rest/incoming-phone-numbers#instance-delete

@mosio
Copy link

mosio commented Dec 11, 2013

You should be able to do that using:

$this->twilio->account->incoming_phone_numbers->delete($sid);

For example (not tested live, but something like this should work):

try {
  $twilio_phone_number = '+15555555555';  
  $nums = $this->twilio->account->incoming_phone_numbers->getIterator(0, 1, array("PhoneNumber" => $twilio_phone_number));
  foreach ($nums as $n) {
    $this->client->account->incoming_phone_numbers->delete($n->sid);
  }
}
catch (Exception $e) {
}

@ghost
Copy link
Author

ghost commented Dec 11, 2013

Thank you both for responding but I have tried that endpoint as follows and it doesn't work, it tells me method not supportd. Here is my code:

$url = '/' . $this->api_version . '/Accounts/' . $this->account_sid . '/IncomingPhoneNumbers.json';

$data = array(
'PhoneNumber' => $phone_number,
);

return $this->_twilio->request($url, 'DELETE', $data);

@mosio
Copy link

mosio commented Dec 11, 2013

Delete is not supported on your URL: https://www.twilio.com/docs/api/rest/incoming-phone-numbers#list-delete

You need to call it specifying the incoming phone number's SID in the url: https://www.twilio.com/docs/api/rest/incoming-phone-numbers#instance

My code should work to retrieve this info if you only know the phone number you want to delete, but it does require two api calls to do the work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants