Facebook Error #100 when uploading Offline Conversions using Marketing API - facebook

I am using the the Facebook Marketing API to upload offline conversions.
The attached code was working until about 2 weeks ago and now reports the following error.
{"error":{"message":"(#100) The parameter data is required","type":"OAuthException","code":100,"fbtrace_id":"HkpzkWB1I5g"}}
I don't understand why it should simply stop working after working as expected for so long. I don't know how to fix it. Any ideas?
$data=array();
$data["match_keys"]["email"]=$emails;
$data["match_keys"]["phone"]=$mobiles;
$data["match_keys"]["fn"]=hash("sha256",$first_name);
$data["match_keys"]["ln"]=hash("sha256",$last_name);
$data["match_keys"]["ln"]=hash("sha256",$last_name);
$data["match_keys"]["ct"]=hash("sha256",$suburb);
$data["match_keys"]["zip"]=hash("sha256",$postcode);
$data["match_keys"]["country"]=hash("sha256","Australia");
$data["event_time"] = strtotime($order_date);
$data["event_name"] = "Purchase";
$data["currency"] = "AUD";
$data["value"] = $order_total;
$data['order_id']=$order_id;
$access_token = '<access_token_0>';
// PURCHASE DATA
$data_json = json_encode(array($data));
$fields = array();
$fields['access_token'] = $access_token;
$fields['upload_tag'] = uniqid() // You should set a tag here (feel free to adjust)
$fields['data'] = $data_json;
$ch = curl_init();
curl_setopt_array($ch, array(
// Replace with your offline_event_set_id
CURLOPT_URL => "https://graph.facebook.com/v2.12/1696501357346693/events",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => http_build_query($fields),
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache",
"content-type: multipart/form-data",
"Accept: application/json" ),
));
$result = curl_exec($ch);
echo "\nResult encode";
echo ($result);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close ($ch);

Same thing just started happening here. Exact same problem. I had to play around for hours... But to get it working, I commented out
//"content-type: multipart/form-data",
and it started to work for me. Please let know if that also solves your problem.

It simply means that data is not sent as per documentation. I was facing this issue as in my case "contents" parameter was passing empty string, instead of documentation says that "contents" parameter should contain atleast 2 parameters, that is, quantity and id.
Go through documentation and you can compare your value format with documentation.
Here is link for documentation :- https://developers.facebook.com/docs/marketing-api/conversions-api/parameters/custom-data#content-ids

Related

Is there a way to fix a date error using Symfony 4?

I'm working on a project as a back-end developer using PHP 7.2.11 and Symfony 4.2.3
My goal is to showcase events (concerts, festivals...) from data I grab from an API on an interactive map.
This is the result I get:
https://imgur.com/HmpBK5B.png
To import the data from the API, I use a for loop going from 1 to 7 (corresponding to days) and adding days to the today's date.
This date will be used as a parameter to grab the events occuring from today to the next 7 days.
Problem is: I get the following error running my custom symfony command
php bin/console import:mapado :
2019-03-26T12:08:34+01:00 [error] Error thrown while running command "import:mapado". Message: "Notice: Undefined index: address"
The error is due to a date not existing and then refering to an inexistant address.
I tried to change the parameters in my first for loop, with days going either to 8 or to 6 but it didn't change the output error.
I change the custom date parameter (from my loop) from the API url to the default parameter and everything is working with default (but it only gets the events for the 3 next days).
Here is the parameter I use:
https://imgur.com/tx1OyrM.png
From: https://api.mapado.net/v2/docs#operation/getActivityCollection
And how an element from the API looks like:
https://imgur.com/l1nTOCC.png
This is the code I've written:
protected function execute(InputInterface $input, OutputInterface $output) {
for ($jour = 0; $jour <= 7; $jour++) {
// problem is here
$futureDay = date('Y-m-d', strtotime('+'.$jour.' days'));
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.mapado.net/v2/activities?fields=#id,title,shortDate,nextDate,activityType,locale,description,address&itemsPerPage=1000&when=".$futureDay."&periodOfDay=evening",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"Authorization: Bearer MTMwZWJiODFiZjA4YTcyOGY2ZmMzMGYwOTQyYWM2NDZjODVlNDg1MzU0MzE3M2I4MTdiMDQyZjU5MDVkZjFjZA",
"Cache-Control: no-cache",
"Conent-Type: application/json",
"Content-Type: application/x-www-form-urlencoded",
"Postman-Token: 55672a19-0ffc-4fe6-a866-3e15c3df9dae"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
$mapado_events = json_decode($response, JSON_PRETTY_PRINT);
for ($i = 0; $i < count($mapado_events['hydra:member']); $i++) {
if ($mapado_events['hydra:member'][$i]['locale'] == 'fr') {
$mapado_id = $mapado_events['hydra:member'][$i]['#id'];
$mapado_date = \date('Y-m-d', strtotime($mapado_events['hydra:member'][$i]['nextDate']));
$result = $this->getContainer()
->get('doctrine')
->getRepository(MapadoIDs::class)
->findOneBy(['mapado_id' => $mapado_id]);
if ($result == null) {
echo 'event existe pas, ajout en bdd'.PHP_EOL;
$MapadoIDs = new MapadoIDs();
$MapadoIDs->setMapadoId($mapado_id);
$this->em->persist($MapadoIDs);
$mapado = json_decode($response, JSON_PRETTY_PRINT);
$event = new Event();
$event->setLongitude($mapado['hydra:member'][$i]['address']['longitude']);
$event->setLatitude($mapado['hydra:member'][$i]['address']['latitude']);
$event->setTitle($mapado['hydra:member'][$i]['title']);
$event->setDate($mapado_date);
$event->setFormattedAddress($mapado['hydra:member'][$i]['address']['formattedAddress']);
$event->setCity($mapado['hydra:member'][$i]['address']['city']);
$event->setLocale($mapado['hydra:member'][$i]['locale']);
$event->setActivityType($mapado['hydra:member'][$i]['activityType']);
$event->setDescription($mapado['hydra:member'][$i]['description']);
$this->em->persist($event);
}
}
}
}
$this->em->flush();
curl_close($curl);
if ($err) {
echo "cURL Error #: " . $err;
} else {
echo $response;
}
}
}
for better readability:
https://pastebin.com/CTu5gb8t
Expected result is a json output in my console.
Actual result is an error thrown preventing me from inserting results into my database.
Could you tell me if I'm missing something that could result in this error ?
It's a long and detailed post so that you can understand better my problem.
Well I solved my problem and it was not a date problem.
The problem was with the itemsPerPage query parameter requesting too much data and then throwing an error.
I set it up to 400 and everything is working as expected.

What is this? (Facebook Offline Conversions API) Error #21009 - The data set upload is temporarily not ready

We have been uploading to Facebook's Offline Conversion API for the past 3 weeks with no issues. Suddenly, Facebook is returning this error:
(#21009) The data set upload is temporarily not ready.
See below code for full JSON payload.
Our Auth Token is still valid. (e.g. Not expired, still valid)
According to this tool: https://developers.facebook.com/tools/debug/accesstoken/
# I had to remove these fields for privacy reasons
define('FACEBOOK_APP_ACCESS_TOKEN', 'YOUR TOKEN HERE');
define('FACEBOOK_PIXEL_OFFLINE_EVENT_SET_ID', 'YOUR PIXEL ID HERE');
# Be sure to change the email/name fields accordingly
$event_name='test-upload';
$data = array();
$data["match_keys"] = array();
$data["match_keys"]['email'] = hash('sha256', 'bob.ross#example.com');
$data["match_keys"]['fn'] = hash('sha256', 'bob');
$data["match_keys"]['ln'] = hash('sha256', 'ross');
$data["match_keys"]['gen'] = hash('sha256', 'm');
$data["event_time"] = time();
$data["event_name"] = $event_name;
$data["currency"] = "USD";
$data["value"] = '0.00';
// Turn Data to JSON
$data_json = json_encode(array($data));
// Fill available fields
$fields = array();
$fields['access_token'] = FACEBOOK_APP_ACCESS_TOKEN;
$fields['upload_tag'] = $event_name . '-' . time(); // You should set a tag here (feel free to adjust)
$fields['data'] = $data_json;
$url = 'https://graph.facebook.com/v3.2/' . FACEBOOK_PIXEL_OFFLINE_EVENT_SET_ID . '/events';
$curl = curl_init($url);
curl_setopt_array($curl, array(
// Replace with your offline_event_set_id
CURLOPT_URL => 'https://graph.facebook.com/v3.2/' . FACEBOOK_PIXEL_OFFLINE_EVENT_SET_ID . '/events',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => http_build_query($fields),
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache",
//"content-type: multipart/form-data",
"Accept: application/json" ),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
Expected result from Facebook:
{"id":"36485444079550","num_processed_entries":1}
Actual result from Facebook
{
"error": {
"message": "(#21009) The data set upload is temporarily not ready.",
"type": "OAuthException",
"code": 21009,
"fbtrace_id": "GeofD5QsXdI"
}
}
I would add a comment instead of an "answer" but I don't quite have the points yet. The commenters on the Facebook thread (https://developers.facebook.com/support/bugs/1052442614962359/) have had this magically resolve overnight, and I experienced the same (problem happening and no explanation, then magical resolution and no explanation). It seems like Facebook may have fixed whatever was causing the issue.

Merge anonymous lead with known lead with Marketo REST API

I have anonymous leads in Marketo and I need to merge them with known leads through the REST API.
I am trying the code below
public function postData() {
$url = $this->host . "/rest/v1/leads/" . $this->id ."/merge.json?access_token=" . $this->getToken() . "&leadIds=" . $this::csvString($this->leadIds);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 120,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache",
"content-type: application/json",
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
}
It is responding with {"requestId":"1af7#fgfdhgfdgfgdfg","success":false,"errors":[{"code":"1004","message":"Lead '231325' not found"}]} but I can see the lead with the id 231325 in Marketo.
How can I merge the anonymous lead with the known lead with REST?
Unfortunately, you cannot do that, or not in a straightforward way.
The description of the Merge functionality in the Docs does not states it as clearly as the Merge Endpoint reference, but it "merges two or more known lead records into a single lead record". So even if you see the MarketoIds of these visitors in the system, the API won't find them in the Leads table.
However, depending on your exact goal and setup, you might solve your issue by using the Associate Web Activity functionality, as it "associates a known Marketo lead record to a munchkin cookie and its associated web activity history". The Associate Endpoint expects the value of the _mkto_trk cookie of a visitor (sample format: id:287-GTJ-838%26token:_mch-marketo.com-1396310362214-46169).
Having said that, your curl would look something like this:
$url = $host . '/rest/v1/leads/' . $leadId . '/associate.json?cookie=' . $cookie . '&access_token=' . $token;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
]);
$response = curl_exec($curl);
curl_close($curl);
You can obtain the value of the cookie with $_COOKIE['_mkto_trk'].

Successful Message Push To StockTwits, Chart Not Showing

I can successfully post a message. However when I try with a chart, I get back a success code (200) with the following URL's in the response:
http://charts.stocktwits.com/production/large_.png
http://charts.stocktwits.com/production/small_.png
When I Try to view the message in StockTwits, I get image not found
http://stks.co/p2kuK
I assume there should be some code after large_ and small_; hence the image not found.
Since no errors came back in JSON Response, I assume everything worked OK.
Link to Chart I'm uploading with API:
http://tradescribe.com/images/performance_graphs/AStrakaus-3GTakeover-5day.png
Any ideas?
The message appears in StockTwits without the Chart so API call looks to be correct
Code
$postdata = array(
'access_token' => <TOKEN>,
'body' => <MESSAGE INFORMATION>,
'chart' => <FULLY QUALIFIED URL TO IMAGE>
);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'https://api.stocktwits.com/api/2/messages/create.json',
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => $postdata
));
We have fixed an issue on our end that was causing this problem and shouldn't be happening anymore.

Unexpected error when tyring to get the payment transactions of a user

I always get an error when tyring to get the payment transactions of a user.
{
"error": {
"message": "An unexpected error has occurred. Please retry your request later.",
"type": "OAuthException",
"code": 2
}
}
I tried several approaches:
// approach 1
$response = $app['facebook']->api('/'.$app['user']['fbUserID'].'/payment_transactions', 'GET', [
//'request_id' => $order['requestID'],
'access_token' => $app['fb.app_id'].'|'.$app['fb.app_secret']
]);
// approach 2
$url = 'https://graph.facebook.com/'.$app['user']['fbUserID'].'/payment_transactions?fields=id&access_token='.$app['fb.app_id'].'|'.$app['fb.app_secret'];
$ch = curl_init();
$options = [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_TIMEOUT => 60,
CURLOPT_HTTPHEADER => array('Expect:'),
CURLOPT_CAINFO => DIR.'/vendor/facebook/php-sdk/src/fb_ca_chain_bundle.crt'
];
curl_setopt_array($ch, $options);
$result = curl_exec($ch);
curl_close($ch);
// approach 3
// like 2 but with a fresh access token
$appAccessToken = explode('=', file_get_contents('https://graph.facebook.com/oauth/access_token?client_id='.$app['fb.app_id'].'&client_secret='.$app['fb.app_secret'].'&grant_type=client_credentials'))[1];
Even in the Graph API Explorer I get this error. Only if I use the commandline it works:
$ curl 'https://graph.facebook.com/........./payment_transactions?access_token=.......|.........'
The user is an test user which is also a payment tester and made successfull test-purchases. The Local Currency Payments Breaking Changes are disabled.
What am I doing wrong?
You need to use an app access token to GET from that endpoint. See https://developers.facebook.com/docs/graph-api/reference/user#payment_transactions for details.