3

Hi I am developing application in salesforce for accessing the google adwords reports data for e.g. ADGROUP_PERFORMANCE_REPORT. I am sending http post request to https://adwords.google.com/api/adwords/reportdownload/v201302, and I am using apex(java like language in salesforce) below is my request.

Http h = new Http();
HttpRequest req = new HttpRequest();
GoogleAuthorization auth=new GoogleAuthorization();
req.setHeader('Authorization', 'GoogleLogin ' + auth.token);
req.setHeader('UserAgent', 'XXXXX');
req.setHeader('developerToken','XXXXXXXX');
req.setHeader('clientCustomerId','XXXXXXXX');
req.setEndPoint('https://adwords.google.com/api/adwords/reportdownload/v201302');
req.setHeader('Content-Type', 'application/x-www-form-urlencoded');
req.setMethod('POST');
string xml='<reportDefinition xmlns="https://adwords.google.com/api/adwords/cm/v201302">'+
          '<selector>'+
            '<fields>CampaignId</fields>'+
            '<fields>Id</fields>'+
            '<fields>Impressions</fields>'+
            '<fields>Clicks</fields>'+
            '<fields>Cost</fields>'+
            '<predicates>'+
              '<field>Status</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>XML</downloadFormat>'+
        '</reportDefinition>';
req.setBody('__rdxml='+EncodingUtil.urlEncode(xml, 'UTF-8'));
HttpResponse res=h.send(req);

After requesting i am getting the AuthenticationError System.HttpResponse[Status=Bad Request, StatusCode=400].

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><reportDownloadError><ApiError><type>AuthenticationError.USER_ID_INVALID</type><trigger>&lt;null&gt;</trigger><fieldPath></fieldPath></ApiError></reportDownloadError>
  • Hi SFIntegrator. Were you able to get this integrated? Would you mind posting your solution? – Swisher Sweet Apr 24 '15 at 15:29
1

The problem is that you are not forming a valid SOAP request - Your issue is not an Apex code one but a SOAP one.

I haven't tested this solution myself but Salesforce has the functionality to build apex classes from WSDLs, try using the AdWords WSDL to generate a class.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.