CURL HTTP POST returns 400 no matter what (report download)

173 views
Skip to first unread message

sws...@gmail.com

unread,
Dec 15, 2016, 11:21:31 AM12/15/16
to AdWords API Forum
Hello,

I'm currently trying to setup the CURL to download a report, since as far as I can tell, I cannot do that via the PHP lib itself (given that the only service I found for reports is the ReportDefinitionService which gets me the forms, not data and AdGroupCriterionService doesn't return info such as clicks, etc.
The code I'm using right now,

$reportDefinition = '<?xml version="1.0" encoding="UTF-8"?>
  <selector>
    <fields>CampaignId</fields>
    <fields>AdGroupId</fields>
    <fields>Impressions</fields>
    <fields>Clicks</fields>
    <fields>Cost</fields>
    <predicates>
      <field>AdGroupStatus</field>
      <operator>IN</operator>
      <values>ENABLED</values>
      <values>PAUSED</values>
    </predicates>
  </selector>
  <reportName>Custom Adgroup Performance Report</reportName>
  <reportType>ADGROUP_PERFORMANCE_REPORT</reportType>
  <dateRangeType>LAST_7_DAYS</dateRangeType>
  <downloadFormat>CSV</downloadFormat>
</reportDefinition>';
$params = array("__rdxml" => $reportDefinition);
$httpHeaders = array('Authorization: Bearer oath2IGotWhileAuthorizingThePhpLib',
'developerToken: myDevToken',
'clientCustomerId: accIdUnderTestMCC',
'Content-Type: multipart/form-data;');

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $params);
curl_setopt($curl, CURLOPT_HTTPHEADER, $httpHeaders);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$page = curl_exec($curl);
curl_close($curl);

400 is what I get all the time. FYI, I'm using the oath I got while I was setting up the php lib, the test dev token and the clientId of a dummy acc under a test MMC acc. Laravel on Valet.

While on the topic of pulling this data, is this the correct way? What I need to do is get stuff such as Keywords/Search terms/Ad extensions as well as their % served, clicks, CTR, avg. pos., etc and after banging my head against the lib wall, I wanted to try this.

Thanks upfront!

Sreelakshmi Sasidharan (AdWords API Team)

unread,
Dec 15, 2016, 4:06:07 PM12/15/16
to AdWords API Forum
Hi, 

Have you checked our samples in PHP for reporting? You could refer to these and follow the same for the specific report that you would like to run from the PHP library. Please explore the Keyword Performance Report for Keywords , Placeholder  Feed Item Report for extensions and Search Query Report for search terms.  The report types chart should be helpful in finding the right report that suits your requirements.

Thanks,
Sreelakshmi, AdWords API Team

sws...@gmail.com

unread,
Dec 19, 2016, 12:26:27 AM12/19/16
to AdWords API Forum
Hello,

I will check them soon.
Before I jump into all of this, though, I'd like to know what would be the recommended way to pull data such as keywords (but not only) stats (clicks, % served, avg. position) etc. The thing I'm supposed to build simply needs to display this data based on the client ID, that's all. Wouldn't a CURL HTTP POST (after I get through my current invalid oauth token issue) be the better way to do this?

Thanks.

Sreelakshmi Sasidharan (AdWords API Team)

unread,
Dec 19, 2016, 2:05:23 PM12/19/16
to AdWords API Forum
Hi, 

The document where the reports are categorized based on the fields might be helpful in your case. All reports provide data aggregated at different level and you can choose them based on your requirement. In your case, Keywords Performance Report includes all statistics aggregated at the keyword level including clicks, average position etc.

You could do the implementation using CURL HTTP POST or any other language of your choice. 

sws...@gmail.com

unread,
Dec 22, 2016, 7:50:17 AM12/22/16
to AdWords API Forum
Hi,

I did continue with the PHP Lib and for now everything seems fine when it comes to the reports. I do have a few questions still. 

I'm supposed to implement a 'Display Network' to the application but I'm not quite sure what it is or even how to get the data for it. Is it simply data based on the ads displayed in graphs and such?

Then, apart from Ads, Keywords, Search Terms and Ad Extensions, the users are supposed to access a few specific Dimensions such as clicks per day, destination URLs, search terms and geographic targeting. Am I correct to assume that Dimensions are basically the same data as normal but filtered and displayed in a different way? If I'm correct, should I then use Destination URL Report for said URLs, Search Query Performance Report again for the search terms and Geo Performance Report for geographic targeting? What is then recommended for the clicks per day Dimension?

Thanks,
swsmeat

Op maandag 19 december 2016 20:05:23 UTC+1 schreef Sreelakshmi Sasidharan (AdWords API Team):

Sreelakshmi Sasidharan (AdWords API Team)

unread,
Dec 22, 2016, 2:14:30 PM12/22/16
to AdWords API Forum
Hi, 

I am linking the documents that will help you understand what a display network is and how to get your Ads on the display network. If you have any specific questions about this please feel free to write back.

Please find the mapping of naming conventions of the reports on the AdWords UI to the API here. It should be helpful in determining which report should you be looking for depending on your use case. 
Reply all
Reply to author
Forward
0 new messages