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-----------------------------------------------------------------
String url = "
https://googleads.googleapis.com/v8/customers/CUSTOMERID/googleAds:search";
String accessToken = "ACCESS_TOKEN";
String query = "SELECT
campaign.id,
campaign.name FROM campaign ORDER BY
campaign.id";
Map<String, String> headers = new HashMap<>();
headers.put("Content-Type", "application/json");
headers.put("developer-token", "DEVELOPER_TOKEN");
headers.put("Authorization", "Bearer " + accessToken);
JSONObject map = new JSONObject();
map.put("query", query);
map.put("pageSize", 1000);
HttpRequest httpRequest = HttpUtil.
createPost(url);
String result = httpRequest.addHeaders(headers).form(map.toJSONString()).timeout(30000).execute().body();
result = UnicodeUtil.
toString(result);
System.
out.println(result);
---------------------------------RESPONSE ERROR---------------------------------------------------------------
{
"error": {
"code": 400,
"message": "Request contains an invalid argument.",
"status": "INVALID_ARGUMENT",
"details": [
{
"errors": [
{
"errorCode": {
"queryError": "UNEXPECTED_END_OF_QUERY"
},
"message": "Error in query: unexpected end of query."
}
],
"requestId": "e3ih8T-AbwobU-1UyYukfg"
}
]
}
}
Process finished with exit code 0
--------------------------------------------------------------------
Would appreciate help on this. Thanks