Getting "Invalid parameter" exception on getReportsStats with no reason - php

Can anyone help me with a fast code review?
$fields = array(
'campaign_id',
'spend'
);
$params = array(
'data_columns' => $fields,
'time_interval' => array(
'day_start' => array(
'year' => 2011,
'month' => 9,
'day' => 1
),
'day_stop' => array(
'year' => 2011,
'month' => 9,
'day' => 10
),
),
);
$stats = $adAccount->getReportsStats(array(), $params);
After running this code I am getting:
<b>Fatal error</b>: Uncaught exception 'FacebookAds\Http\Exception\AuthorizationException' with message 'Invalid parameter' in /home/maciekmp/public_html/face_test/FacebookAds/Http/Exception/RequestException.php:129
fdfd

I found the following in the facebook api developer docs. Search on "async". If the data you are querying is too old you will have to do an asynchronous call to the graph api. Which is usually the case with the error you received. The current version of the php-sdk does not support passing an async parameter out of the box. Since AdAccount defaults to GET request and async calls to the graph api must be done with POST request, you will need to extend the AdAccount class and create and prepare a request to use the POST method.

I found that when you try get more than 30 days of to the current date it shows this error.
29 days of data and it works, which is rather pointless! I'm going to ask in their developer forum.
$fields = array('campaign_id', 'total_actions', 'spend'); // The fields I ask for?
$params = array(
'data_columns' => array (
'campaign_group_id',
'total_actions',
'social_impressions',
'impressions',
'unique_impressions',
'clicks',
'spend',
'impressions',
// 'action_values_28d_view'
),
'time_interval'=>array(
'time_start'=>mktime(0,0,0,1,17,2015),
'time_stop'=>mktime(0,0,0,date("n"),date("d"),date("Y"))
),
/*
'time_ranges'=>array(
array(
'day_start'=>array(
'day'=>1,
'month'=>1,
'year'=>2015,
),
'day_stop'=>array(
'day'=>13,
'month'=>2,
'year'=>2015,
),
),
),
*/
// 'date_preset' => 'last_28_days',
'time_increment'=>1,
);

Related

API Error 401 - Error connecting to the API

We began seeing these DocuSign exceptions 09/24/2019:
DocuSign \ eSign \ ApiException (401)
[401] Error connecting to the API (https://NA3.docusign.net/restapi/v2/login_information)
None of the code surrounding our DocuSign logic has been touched for almost six months. So I'm at a loss as to why this exception is being thrown.
We're using the following packages (relating to this):
laravel/framework v5.8.35
docusign/esign-client 3.0.1
tucker-eric/docusign-rest-client 1.0.0
tucker-eric/laravel-docusign 0.1.1
I've tried to update the packages with composer thinking they might have made updates to fix something, but it didn't change anything other than throw USER_AUTHENTICATION_FAILED instead of the exceptions' message above.
As I said, no code has been touched, and I have very little experience with the DocuSign API, and making matters worse this was an old developer's code...
I am able to hit the endpoint, and authenticate with our credentials, using Postman and it seems to work fine. So again, I'm not sure how this just started happening.
The code from our controller:
$parcel = request('parcel_id');
$subdivision = $user->subdivision_id;
$subEmail = Subdivision::where('id', $user->subdivision_id)->pluck('email')->first();
$move = Move::create([
'full_name' => request('full_name'),
'email' => request('email'),
'phone_number' => request('phone_number'),
'parcel_id' => $parcel,
'direction' => request('direction'),
'action_date' => request('action_date'),
'user_id' => auth()->id(),
'subdivision_id' => $subdivision
]);
$residentTabs = array(
array(
'tabLabel' => env('MOVE_IN_ADDRESS_FIELD'),
'value' => $move->parcel->MailingAddress
),
array(
'tabLabel' => env('MOVE_IN_DATE_RESIDENT_FIELD'),
'value' => $move->action_date->format('m/d/Y')
),
array(
'tabLabel' => env('MOVE_IN_EMAIL_FIELD'),
'value' => $move->email
),
array(
'tabLabel' => env('MOVE_IN_PRIMARY_PHONE_FIELD'),
'value' => $move->phone_number
),
array(
'tabLabel' => env('MOVE_IN_FULL_NAME_FIELD'),
'value' => $move->full_name
)
);
$pmTabs = array(
array(
'tabLabel' => env('MOVE_IN_PM_ADDRESS_FIELD'),
'value' => $move->parcel->MailingAddress
),
array(
'tabLabel' => env('MOVE_IN_PM_DATE_FIELD'),
'value' => $move->action_date->format('m/d/Y')
),
);
$templateRoles = array(
array(
'email' => $move->email,
'name' => $move->full_name,
'roleName' => 'Resident',
'tabs' => array(
'textTabs' => $residentTabs
)
),
array(
'email' => $subEmail,
'name' => $user->name,
'roleName' => 'Property Manager',
'tabs' => array(
'textTabs' => $pmTabs
)
)
);
$envelopeDefinition = array(
'status' => 'sent',
'templateId' => env("DOCUSIGN_TEMPLATE_ID"),
'templateRoles' => $templateRoles
);
$contract = DocuSign::get('envelopes')->createEnvelope($envelopeDefinition);
The last line is where the exception is thrown, and the function throwing the exceptions is:
vendor/docusign/esign-client/src/ApiClient.php::callApi
We expect it to work as it has, throwing no exceptions and creating the envelope successfully.
However, we have been seeing USER_AUTHENTICATION_FAILED and general 401 exceptions.
Any help is appreciated!
Your token may have expired. Not sure how it was created and what authentication mechanism you are using. You need to check where is the token and the header in the REST API calls that is using it. It may be that was hardcoded, or was there a refresh token used to keep obtaining new tokens and that process broke.
If you're getting an Authentication failure while trying to hit the login_information endpoint, it's likely that your application is using Legacy Header authentication with an invalid password.
I'd recommend the following:
Try to log in to the web console at www.docusign.net, and perform a Password Reset if necessary
Once you are able to log in, update the stored credentials in the application
2FA or forced Single Sign-On will both block Legacy Header auth. If either is in place, they will need to be disabled, or you will need to switch to one of the Account Server auth workflows.

Facebook Marketing API get campaign info

I'm using the code autogenerated by facebook to try and connect to the marketing API to get campaign stats. In doing so, I'm getting:
Uncaught FacebookAds\Http\Exception\AuthorizationException: (#100) results, actions:like, video_play_actions:video_view, video_avg_time_watched_actions:video_view, unique_actions:link_click are not valid for fields param.
$fields = array(
'results',
'reach',
'actions:like',
'video_play_actions:video_view',
'video_avg_time_watched_actions:video_view',
'unique_actions:link_click',
);
var_dump($fields);
$params = array(
'level' => 'campaign',
'filtering' => array(array('field' => 'campaign.delivery_info','operator' => 'IN','value' => array('active'))),
'breakdowns' => array(),
'time_range' => array('since' => '2017-05-19','until' => '2019-05-19'),
);
echo json_encode((new AdAccount($ad_account_id))->getInsights(
$fields,
$params
)->getResponse()->getContent(), JSON_PRETTY_PRINT);
Above I used campaign.delivery_info per this answer. I've also tried (per the auto-generated code):
'filtering' => array(array('field' => 'delivery_info','operator' => 'IN','value' => array('active')))
Seems you are asking for old values field, try this:
$fields = array(
'reach',
'actions',
'video_play_actions',
'video_avg_time_watched_actions',
'outbound_clicks',
);
Hope this help
NB: results field is not available

QUICKBASE PHP SDK add_record returns blank response

I was recently brought on by a company that uses Quickbase. They have limited systems in place to talk to the Quickbase application, so I am trying to incorporate the PHP SDK in order to add/edit records in Quickbase using a front end designed by myself so customers can submit a form from the web into Quickbase.
I'm coming across a problem right away trying to get the SDK to even respond with something other than an error. Currently it doesn't respond with anything when trying to add a record.
I keep reading that a recent (~2-3 years ago) change has caused this to be a bit difficult to use.
below is my codesnippet from a php page called "addnewcustomer.php"
include_once('quickbase.php');
//my PHP SDK Options located inside quickbase.php
var $user_name = 'username'; // QuickBase user who will access the QuickBase
var $passwd = 'pw'; // Password of this user
var $db_id = 'dbid'; // Table/Database ID of the QuickBase being accessed
var $app_token = 'my app token';
var $xml = true;
var $user_id = '';
var $qb_site = "www.mycompany.quickbase.com";
var $qb_ssl = "https://www.mycompany.quickbase.com/db/";
var $ticketHours = 12;
$quickbase = new QuickBase('myusername', 'mypw', true, "dbid", "token", "realm", hour);
$fields = array(
array(
'fid' => '148',
'value' => $agentid), //agentid
array(
'fid' => '15',
'value' => $city), //city
array(
'fid' => '16',
'value' => $state), //state
array(
'fid' => '14',
'value' => $address), //address
array(
'fid' => '524',
'value' => $apt), //apt #
array(
'fid' => '17',
'value' => $zip), //zip code
array(
'fid' => '33',
'value' => $rentown), //rent/own
array(
'fid' => '28',
'value' => $first), //first name
array(
'fid' => '29',
'value' => $last), //last name
array(
'fid' => '21',
'value' => $email), //email
array(
'fid' => '18',
'value' => $phone) //phone
);
$quickbase->add_record($fields);
It currently responds with nothing, ie. blank response. If I change the realm with something inaccurate I get an error of "Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML'", which makes me think I have everything setup correctly.
What should a successful entry return? What am I doing wrong?
The add_record method should be returning an XML object. If you capture that object, you can check it to see if the API call was successful or if an error was returned. So, if you change your code to:
$results = $quickbase->add_record($fields);
print_r($results);
You'll get something you can understand. It's inelegant, but it will show you quickly if you're getting a response and if that response is an error. You should see something like this on success:
SimpleXMLElement Object ( [action] => API_AddRecord [errcode] => 0 [errtext] => No error [rid] => 81 [update_id] => 1436476140453 )

How to Access Transaction Array Value from IPN

I am trying to parse an IPN callback from paypal. The type of payment is adaptive, so there is an array of transactions (even though I will only have 1).
Here is a sample IPN with some fields pruned for readability:
array (
'payment_request_date' => 'Fri Jan 30 22:28:54 PST 2015',
'verify_sign' => 'removed',
'transaction[0].id_for_sender_txn' => 'removed',
'transaction[0].receiver' => 'removed',
'cancel_url' => '#pruned',
'transaction[0].is_primary_receiver' => 'false',
'pay_key' => '#removed',
'action_type' => 'PAY',
'transaction[0].id' => 'id is here',
'transaction[0].status' => 'Completed',
'transaction[0].paymentType' => 'SERVICE',
)
I am trying to access the value of 'transaction[0].id' and cannot get it to dump. I have tried basically every possible way I can think of:
$id = $_POST['transaction'][0]['id'];
$id = $_POST['transaction[0].id'];
Also tried asking the array to a var and then using that:
$id = $array->transaction[0].id;
This should give you the info you need.

Multiple elements of same name in PHP SOAP Call

I know this type of question has been asked a number of times. I have spent several hours reading and trying the offered solutions - but none appear to work for my situation.
I need to send a SOAP request to an API that can contain an element that repeats like so:
<operationNumbers>
<operationNumber>1234</operationNumber>
<operationNumber>1235</operationNumber>
<operationNumber>1236</operationNumber>
<operationNumber>1237</operationNumber>
</operationNumbers>
I did read that perhaps I could do this:
$buildRequest = Array(
'myheader' => Array(
'date' => MY_DATE,
'id' => Array(
'client' => CLIENT,
'clientRef' => MYREF
)
),
'operationNumbers' => Array (
Array('operationNumber' => '1234'),
Array('operationNumber' => '1235')
)
);
$request = $client->__soapCall( 'getMultiOpDets', array($buildRequest) );
Sadly this does not work and results in 'invalid request', if I send in a single operation number eg:
...
'operationNumbers' => Array (
'operationNumber' => '1234'
)
...
The request is successful. I've tried soapVars/soapParams but cannot get it working using this approach. Any hints/tips/help appreciated.
So, I solved it.
$operationNumbersArray = array('1234','1235');
...
'operationNumbers' => array(
'operationNumber' => $operationNumbersArray
)
During my testing and fiddling about, I had inadvertently removed another value that was mandatory. The API did not give warning of it's omission (sadly).
Here is the code I use:
$wsdl = 'https://your.api/path?wsdl';
$client = new SoapClient($wsdl);
$multipleSearchValues = [1, 2, 3, 4];
$queryData = ['yourFieldName' => $multipleSearchValues];
$results = $client->YourApiMethod($queryData);
print_r($results);

Categories