3
require 'vendor/autoload.php';
use Plivo\RestAPI;

$auth_id = "My AUTH_ID";
$auth_token = "My AUTH_TOKEN";

$p = new RestAPI($auth_id, $auth_token);
$params = array(
        'number' => '12512077502' # Phone number to buy
    );
$response = $p->get_number($params);
print_r ($response);

It Will Give me Error Message

Array ( 
    [status] => 404 
    [response] => Array ( 
          [api_id] => 0b6214ee-aec4-11e5-ae4f-22000ac69a0d 
          [error] => not found 
 ) )

See here https://www.plivo.com/docs/getting-started/phone-number-api/#rent-a-number

Mukesh Kumar
  • 172
  • 9

2 Answers2

1

You seem to be using the wrong function (get_number) from the python helper library. The correct one is "buy_phone_number" function which uses PhoneNumber API.

Reference - https://github.com/plivo/plivo-python/blob/master/plivo.py#L175

Ramya Raghu
  • 409
  • 3
  • 4
0

I was using the Python plivo module and had the same problem.

From Plivo Support: "Use the new API: https://www.plivo.com/docs/api/number/phonenumber/#buy-number "

What I found that the the plivo module uses the wrong URL when renting a phone number. My work around is to make the call without the helper library. The following is Python code but it might help give you an idea what to do.

import requests

params = {
        'number' : phone_number # Phone number to buy
        }

host = 'https://api.plivo.com/v1/Account/%s/PhoneNumber/%s/' % \
       (account_sid, phone_number)

r = requests.post(host, timeout=5, json=params, auth=(account_sid, auth_token))
assert r.status_code == 201, 'r.status_code=%s' % `r.status_code`

Update: The above might not be necessary after all. I just got an update from Plivo support. The new method name is buy_phone_number() instead of get_number(). That solved the problem for me. I assume the same is true for the PHP library.

JohnMudd
  • 13,607
  • 2
  • 26
  • 24