Reputation: 41
While uploading offline conversion to DoubleClick Search by using google-api-php-client library i encountered following error.
Fatal error: Uncaught exception 'Google_Service_Exception' with message '{ "error": { "errors": [ { "domain": "global", "reason": "requestValidation", "message": "The request was not valid. Details: [Empty batch encountered.]" } ], "code": 400, "message": "The request was not valid. Details: [Empty batch encountered.]" } } ' in /var/www/ds3/vendor/google/apiclient/src/Google/Http/REST.php:118 Stack trace: #0 /var/www/ds3/vendor/google/apiclient/src/Google/Http/REST.php(94): Google_Http_REST::decodeHttpResponse(Object(GuzzleHttp\Psr7\Response), Object(GuzzleHttp\Psr7\Request), 'Google_Service_...') #1 [internal function]: Google_Http_REST::doExecute(Object(GuzzleHttp\Client), Object(GuzzleHttp\Psr7\Request), 'Google_Service_...') #2 /var/www/ds3/vendor/google/apiclient/src/Google/Task/Runner.php(176): call_user_func_array(Array, Array) #3 /var/www/ds3/vendor/google/apiclient/src/Google/Http/REST.php(58): Google_Task_Runner->run() #4 /var/www/ds3/vendor/google/apiclient/src/Google/Client.php(788) in /var/www/ds3/vendor/google/apiclient/src/Google/Http/REST.php on line 118
Using following code to insert new conversion
putenv('GOOGLE_APPLICATION_CREDENTIALS=PATH_TO_SERVICE_ACCOUNT_JSONFILE.json');
$Client = new Google_Client();
$Client->useApplicationDefaultCredentials();
$Client->addScope(Google_Service_Doubleclicksearch::DOUBLECLICKSEARCH);
$DS3 = new Google_Service_Doubleclicksearch($Client);
$Conversion = new Google_Service_Doubleclicksearch_Conversion();
$Conversion->setClickId('MY_GCLID');
$Conversion->setConversionId('MY_CONV_ID');
$Conversion->setConversionTimestamp('MY_CONV_TIMESTAMP');
$Conversion->setSegmentationType('FLOODLIGHT');
$Conversion->setSegmentationName('MY_FLOODLIGHT_ACTIVITY_NAME');
$Conversion->setSegmentationType('ACTION');
$ConversionList = new Google_Service_Doubleclicksearch_ConversionList();
$ConversionList->setConversion($Conversion);
$Response = $DS3->conversion->insert($ConversionList);
print_r($Response);
Upvotes: 2
Views: 429
Reputation: 474
Took me a while today - but I think I was able to recreate your issue AND find a solution. The trouble lies in the way the conversion list is built.
With your current approach, you'll get an object that looks something like:
{
{
"clickId": "MY_GCLID",
"segmentationName": "MY_SEGMENTATION_NAME",
.
.
.
}
}
What you want, is something like this:
{
"conversion": [{
"clickId": "MY_CLICK",
"conversionId": "MY_CONV",
"conversionTimestamp": "MY_TIME",
"currencyCode": "USD",
"revenueMicros": "SOMEMONEY",
"type": "TRANSACTION"
}],
"kind": "doubleclicksearch#conversionList"
}
The alteration to your code would be around the list itself:
$ConversionList = new Google_Service_Doubleclicksearch_ConversionList();
$ConversionList->setKind('doubleclicksearch#conversionList');
$ConversionList['conversion'] = [$Conversion]; // iterator magic
Upvotes: 0