PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, November 19, 2022

[FIXED] How to delete a phone number with Twilio PHP SDK?

 November 19, 2022     php, twilio, twilio-api, twilio-php     No comments   

Issue

I am using Twilio PHP SDK. I have the sid of a phone number. How do I delete it?

The rest API docs shows a delete method but does not have the code for it.

https://www.twilio.com/docs/api/rest/incoming-phone-numbers#list

I've seen some examples on Stack Overflow, but they all seem to be using an older version of the SDK.


Solution

Inspired from here: https://www.twilio.com/docs/api/rest/incoming-phone-numbers?code-sample=code-get-an-incomingphonenumber&code-language=php&code-sdk-version=5.x

Example code to delete() a Twilio phone number:

<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once '/path/to/vendor/autoload.php'; // Loads the library
use Twilio\Rest\Client;

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$token = "your_auth_token";
$client = new Client($sid, $token);

// Delete a Twilio number based on its sid. If you do not have a sid,
// check out the list resource examples on this page
$number = $client
    ->incomingPhoneNumbers("PN2a0747eba6abf96b7e3c3ff0b4530f6e")
    ->delete();

Warning: Once the number is deleted, any code using it, won't work. Be sure you really want to run the code above.



Answered By - Alex Baban
Answer Checked By - David Goodson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing