0
votes

I am using the Twilio PHP helper library.

I have several subaccount credentials stored in the database. Each subaccount usually has several outgoing caller ids associated with it.

I use the credentials for each subaccount to get the outgoingCallerIds.

From the data returned, I take the subaccount SID (AC) and the number SID (PN).

I follow the documentation and am receiving errors on each attempt to update master with the numbers from the subaccounts.

Caught exception: [HTTP 404] Unable to update record: The requested resource /2010-04-01/Accounts/ACxxxxxxxxxxxxxx/IncomingPhoneNumbers/PNxxxxxxxx.json was not found

I have checked the account sids and number sids and they are correct.

Any idea where I'm going wrong here?

Here is my Try that happens in a foreach which credentials for every subaccount.

try
{
    $client = new Client($sid, $token); //subaccount sid and token from not shown foreach
    $caller_ids = $client->outgoingCallerIds->read();

    foreach ($caller_ids as $caller_id)
    {
        $phone_number = $caller_id->phoneNumber;
        $friendly_name = $caller_id->friendlyName;
        $number_sid = $caller_id->sid;
        $account_sid = $caller_id->accountSid;

        $incoming_phone_number = $master_account->incomingPhoneNumbers("$number_sid")
            ->update(
                array("accountSid" => "$account_sid")
            );
    }
}
1

1 Answers

0
votes

Twilio developer evangelist here.

I believe the issue here is that you are using the master account sid to refer to the number that sits within the subaccount thus getting a 404. Instead you should select the subaccount from within the master account's list of accounts, and use that subaccount object to refer to the number as you transfer it.

For example:

$subaccount = $master_account->accounts($subaccount_sid);
$incoming_phone_number = $subaccount->incomingPhoneNumbers($number_sid)
        ->update(
            array("accountSid" => $master_account->sid)
        );

Let me know if this helps at all.