"UNEXPECTED_END_OF_QUERY Error" - Fetching Query Results through HTTP/JSON Combination in Google Ads API

62 views
Skip to first unread message

Harshit Gupta

unread,
Jan 27, 2020, 6:09:56 PM1/27/20
to AdWords API and Google Ads API Forum
Hello everyone,

I am trying to fetch query results through HTTP/JSON Combination in Google Ads API. I am making the request from Google Apps Script. However, I am consistently getting an error code "UNEXPECTED_END_OF_QUERY" for all syntax of Query. Strangely, even when I delete the query statement, I get the same error. Can you please help me identify the cause of error and resolve the same?

-----------------------------------CODE-----------------------------------------------------------------
var url = 'https://googleads.googleapis.com/v2/customers/CUSTOMERID/googleAds:search'; var headers = { 'Authorization': 'Bearer '+ ACCESSTOKEN, 'developer-token': DEVELOPERTOKENKEY', 'contentType': 'application/json', }; data = { "query": "SELECT campaign.id, campaign.name FROM campaign ORDER BY campaign.id" };
var options = { 'headers':headers, 'method':'post', 'muteHttpExceptions':true, "Parameters": data
};

var response = UrlFetchApp.fetch(url, options);
Logger.log(response.getContentText());

---------------------------------RESPONSE ERROR---------------------------------------------------------------

{
"error": { "code": 400, "message": "Request contains an invalid argument.", "status": "INVALID_ARGUMENT", "details": [ { "@type": "type.googleapis.com/google.ads.googleads.v2.errors.GoogleAdsFailure", "errors": [ { "errorCode": { "queryError": "UNEXPECTED_END_OF_QUERY" }, "message": "Error in query: unexpected end of query." } ] } ] } }

--------------------------------------------------------------------

Would appreciate help on this. Thanks

Google Ads API Forum Advisor Prod

unread,
Jan 28, 2020, 2:29:58 PM1/28/20
to harshitg...@gmail.com, adwor...@googlegroups.com
Hi Harshit,

Since you are using Google Ads Scripts, I'd suggest reaching out to the Google Ads Scripts forum as they will be better suited to help you on this.

Regards,
Anthony
Google Ads API Team

ref:_00D1U1174p._5001USx26z:ref

Harshit Gupta

unread,
Jan 28, 2020, 2:50:22 PM1/28/20
to Google Ads API Forum Advisor Prod, adwor...@googlegroups.com
Hi Google Team,

I AM USING Google Ads API, not Google Ads Script. 

The Google ads API is being called from Apps script (NOT Google Ads Script) through an http/url fetch call. 

Thanks in advance.

Warm Regards,
Harshit Gupta 

Harshit Gupta

unread,
Feb 2, 2020, 6:42:54 PM2/2/20
to AdWords API and Google Ads API Forum
Hi Google Team, 

Can you please answer this? Still getting that error making call through HTTP request to Google Ads API.

Google Ads API Forum Advisor Prod

unread,
Feb 3, 2020, 3:05:59 PM2/3/20
to harshitg...@gmail.com, adwor...@googlegroups.com
Hi Harshit,

My last message must not have gone through:
I'm unfamiliar with Apps Script, so you may want to check with them to see if you have any syntax issues. However, by taking a look at your code, I see you have   'developer-token': DEVELOPERTOKENKEY'. You'll need to change this to   'developer-token': + DEVELOPERTOKENKEY.
Reply all
Reply to author
Forward
0 new messages