I am trying to remove a number from my Twilio account using the following code:
// remove the number from Twilio
$client = new Services_Twilio(TWILIO_SID, TWILIO_TOKEN);
try {
// Remove the number
$purchaseNumber = $client->account->incoming_phone_numbers->delete(array(
"PhoneNumber" => "+447903000000"
));
} catch (Exception $e) {
echo 'Error = '.$e->getMessage();
}
Which throws the following exception:
Error = The requested resource /2010-04-01/Accounts/jhsdkfjhdsjhf32370685sjhgfjhdsjfgsdjh/IncomingPhoneNumbers/Array.json was not found
I assume that the format of the request to delete the number is wrong but there doesn't seem to be any examples in the documentation on how to do it - can anyone shed any light on where I am going wrong?
So it seems that you cannot delete a number using the number - you have to use the SID which is returned when you purchase the number. Details here:
http://web.onassar.com/blog/2012/06/16/twilio-incoming-phone-numbers-releasing-deletion/
Related
I am trying to run the following code with the new Google Business Profile API:
$mybusinessbusinessinformationService = new Google\Service\MyBusinessBusinessInformation($client);
try
{
$locations = $mybusinessbusinessinformationService->accounts_locations->call('list',['parent'=>'accounts/1111111111111111111']);
var_dump($locations);
} catch(Exception $e){
var_dump(print_r($e->getMessage(),1));
}
But I am getting the following error:
(list) missing required param: 'parent'
As far as I can tell it seems that I am parsing the param properly.
For people that are searching for an answer:
Since Google updated its API, it's a requirement to parse readMask as well:
$mybusinessbusinessinformationService = new Google\Service\MyBusinessBusinessInformation($client);
$params = array('readMask'=> "title,name");
$locations = $mybusinessbusinessinformationService->accounts_locations->listAccountsLocations($getAccountName,$params);
var_dump($locations);
You can find the mask parameters here:
https://developers.google.com/my-business/reference/businessinformation/rest/v1/locations
I am trying to check for toll-free numbers, and it is working as expected. However, my problem is that some countries don't have the TollFree numbers.
Using the same code on these countries throws a 404 error and stops the code there.
The only way I could think of is making a massive if statement and adding each country manually which offers toll-free option, but I don't like this solution at all as it will be hardcoded. Is there a way to overcome this issue, so it works for the countries that has the .json and ignore the ones that doesn't (instead of crashing the code)?
$twilio = new Client(env('TWILIO_ID'), env('TWILIO_TOKEN'));
$iso = 'CY';
$params = ["excludeLocalAddressRequired" => "true"];
$tollFreeNumbers = $twilio->availablePhoneNumbers($iso)->tollFree->read($params);
This is the response:
"[HTTP 404] Unable to fetch page: The requested resource /2010-04-01/Accounts/ACxxxxx/AvailablePhoneNumbers/CY/TollFree.json was not found"
Using this code will crash with CY but will work with UK, US, CA and many more. Should I add an if statement with hardcoded countries? (I really dislike this solution, but this is what I can think of). What I mean is:
if ($iso == 'GB' || $iso == 'US' || $iso == 'CA') { // and many more
$tollFreeNumbers = $twilio->availablePhoneNumbers($iso)->tollFree->read($params);
}
Twilio developer evangelist here.
Rather than guarding up front with a conditional (which could become out of date as we add toll free numbers in other countries in the future), why not catch the error and return a message to the user to say that toll free numbers are not available in the country they are searching in.
Something like:
try {
$tollFreeNumbers = $twilio->availablePhoneNumbers($iso)->tollFree->read($params);
} catch (Exception $e) {
$tollFreeNumbers = [];
$message = "Toll free numbers are not available in this country.";
}
Let me know if that helps at all.
Why not just wrap it in a try catch?
try {
$tollFreeNumbers = $twilio->availablePhoneNumbers($iso)->tollFree->read($params);
} catch(\Exception $e) {
$tollFreeNumbers = [];
}
i made simple PHP code to show uniquePageViews for my website. The main code was for 7days, but i want to make it lifetime and when i made start-date: "2017-10-5" it start shows me errors. But documentation says that i can place date in that type.
Work variant:
try {
$result = $service->data_ga->get( $GA_VIEW_ID, '100daysAgo', 'today','ga:uniquePageviews');
$count = $result->totalsForAllResults['ga:uniquePageviews'];
echo $count;
} catch(Exception $e) {
var_dump($e);
}
Fail variant:
try {
$result = $service->data_ga->get( $GA_VIEW_ID, '2017-10-5', 'today','ga:uniquePageviews');
$count = $result->totalsForAllResults['ga:uniquePageviews'];
echo $count;
} catch(Exception $e) {
var_dump($e);
}
From the documentation you linked (Emphasis mine) :
All Analytics data requests must specify a date range. If you do not include start-date and end-date parameters in the request, the server returns an error. Date values can be for a specific date by using the pattern YYYY-MM-DD or relative by using today, yesterday, or the NdaysAgo pattern. Values must match [0-9]{4}-[0-9]{2}-[0-9]{2}|today|yesterday|[0-9]+(daysAgo).
Which means your day must be displayed with two digits. Try 2017-10-05 as your start date.
I have tried everything I can possibly think of, and nothing I do helps. I have even gone so far as to download the sample "Pizza Store" application they have on github. Every time, when I replace the "EndPoint" in the sdk-config.ini with "live" and then put in my clientID and clientSecret, and update the bootstrap.php file with that information, that I get from the "my Apps" section I get the error "Got Http response code 400 when accessing https://api.paypal.com/v1/vault/credit-cards."
I am even just using the sample application they provide, and I get that error. I have been searching and searching, and it look slike there are a good 40 different end points, but no documentation on how to use them, how to set them, or anything about it. The only thing I can gather from the sample app is that you can set the "mode" to live in the "setConfig" call, but that just results in the 400 error. I am desperate, I need some help here. I have even emailed their support, and haven't gotten a response. I am trying to help a friend out and get a website up where people can buy things, but this 400 error is driving me insane. Here is a direct copy of my code I am using to try this out...
$config = Config::getItem('merchant_settings', 'paypal');
$config = $config['production'];
$sdkConfig = array('mode' => 'live');
$apiContext = new ApiContext(new OAuthTokenCredential($config['client_id'], $config['client_secret']));
$apiContext->setConfig($sdkConfig);
$card = new CreditCard();
$card->setType('visa');
$card->setNumber('4446283280247004');
$card->setExpireMonth('11');
$card->setExpireYear('2018');
$card->setFirstName('Joe');
$card->setLastName('Shopper');
$funding_instrument = new FundingInstrument();
$funding_instrument->setCreditCard($card);
$payer = new Payer();
$payer->setPaymentMethod('credit_card');
$payer->setFundingInstruments($funding_instrument);
$amount = new Amount();
$amount->setCurrency('USD');
$amount->setTotal('15.85');
$transaction = new Transaction();
$transaction->setAmount($amount);
$transaction->setDescription('A test purchase');
$payment = new Payment();
$payment->setIntent('sale');
$payment->setPayer($payer);
$payment->setTransactions(array($transaction));
try {
$res = $payment->create($apiContext);
$this->set('data' , $res);
} catch(PayPalConnectionException $ex) {
$this->set('data', $ex);
} catch(Exception $e) {
$this->set('data', $e);
}
echo '<pre>';
print_r($data);
echo '</pre>';
And the error I am getting back is...
{"name":"MALFORMED_REQUEST","message":"Incoming JSON request does not map to API request","information_link":"https://developer.paypal.com/webapps/developer/docs/api/#MALFORMED_REQUEST","debug_id":"2c61b8ecedfc6"}
I don't understand, I am using the exact same code as the sample application. Why am I getting that error. I have gone to that link, no help what so ever. Please, I am begging please help.
Yes, I realize that card information is fake, but I should be getting a credit card declined error, not a malformed request error. Please.
I don't know PHP but I think funding instrument is supposed to an array:
"payer":{
"payment_method":"credit_card",
"funding_instruments":[
{
"credit_card":{
If you create a funding instrument array ($fiArray) of length one, and set the first element to $funding_instrument, and pass the array to $payer->setFundingInstruments(fiArray).
Using the following code I am able to get the logs of calls and SMS's. How do I modify this code to only search between certain dates using PHP?
// Instantiate a new Twilio Rest Client
$client = new Services_Twilio($AccountSid, $AuthToken, $ApiVersion);
// http://www.twilio.com/docs/quickstart...
try {
// Get Recent Calls
foreach ($client->account->calls as $call) {
echo "Call from $call->sid : $call->from to $call->to at $call->start_time of length $call->duration $call->price <br>";
}
}
catch (Exception $e) {
echo 'Error: ' . $e->getMessage();
}
You will want to add a code snippet that looks something like this:
$client = new Services_Twilio('AC123', '123');
foreach ($client->account->calls->getIterator(0, 50, array(
'StartTime>' => '2012-04-01',
'StartTime<' => '2012-05-01'
)) as $call) {
echo "From: {$call->from}\nTo: {$call->to}\nSid: {$call->sid}\n\n";
}
If you want to filter the list, you have to construct the iterator yourself with the getIterator command. There's more documentation here: Filtering Twilio Calls with PHP
User search terms StartTime> and StartTime< for this. First one means call start time is greater than and last one means call start time is less than.
To find every calls that started between 4th and 6th July of 2009 add search term
array(
'StartTime>' => '2009-07-04',
'StartTime<' => '2009-07-06'
)
See example 4 on the twilio doc.
Also note you can always ask twilio support. They usually help gladly.