UNEXPECTED_END_OF_QUERY Accessing Google Ads API via Google Apps Script

57 views
Skip to first unread message

Suchitra Theruvath

unread,
Nov 1, 2021, 6:29:25 AM11/1/21
to AdWords API and Google Ads API Forum
Hi,

I am trying to access Google Ads API via Google Apps Script using the below code.


function getGoogleAdsOAuthService() 
{
  console.log("getGoogleAdsOAuthService");
  return OAuth2.createService("googleads.googleapis.com")
      .setAuthorizationBaseUrl(AUTHORIZATION_URL)
      .setTokenUrl(TOKEN_ACCESS_URL)
      .setClientId(CLIENT_ID)
      .setClientSecret(CLIENT_SECRET)
      .setProjectKey(ScriptApp.getProjectKey())
      .setCallbackFunction('authCallback')
      .setPropertyStore(PropertiesService.getUserProperties())
      .setParam('access_type', 'offline')
      .setParam('approval_prompt', 'force')
      .setScope(ADWORDS_SCOPE)
}

function getReport(clientId, reportDefinition, skipReportHeader, skipColumnHeader, skipReportSummary) {
  var service = getGoogleAdsOAuthService();
  //nsole.log(service);
  var options = {
    method: 'POST',
    muteHttpExceptions: true,
    Host : 'googleads.googleapis.com',
    headers: {'developer-token': DEVELOPER_TOKEN,
              'login-customer-id': clientId,
              'Authorization': 'Bearer ' + service.getAccessToken(),
             },
    body: {
      'query': reportDefinition,
    },
  };
  console.log("Options:");
  console.log(options);
  var res = UrlFetchApp.fetch(REPORT_URL, options);
  var output = [];
  console.log(res);
  return res; 
}

here query is "SELECT campaign.id FROM campaign WHERE campaign.status = 'ENABLED' AND campaign.serving_status = 'SERVING'"

This is resulting in UNEXPECTED_END_OF_QUERY. What am I missing ?

Regards,
Suchitra

Google Ads API Forum Advisor

unread,
Nov 2, 2021, 2:33:41 AM11/2/21
to adwor...@googlegroups.com
Hi Suchitra,

Thank you for providing further details to your concern.

I can see that you've already sent a private thread to my team for this concern. With this, let us continue the discussion of this concern to that email thread and provide there the complete request and response logs with request ID and request header generated on your end where we can see the error.

Regards,
Google Logo
Ernie John Blanca Tacata
Google Ads API Team
 


ref:_00D1U1174p._5004Q2QGsl5:ref
Reply all
Reply to author
Forward
0 new messages