UNEXPECTED_END_OF_QUERY

171 views
Skip to first unread message

林跃帆

unread,
Nov 1, 2021, 2:34:17 AM11/1/21
to Google Ads Scripts 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-----------------------------------------------------------------
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"
      }
    ]
  }
}

{"query":"SELECT campaign.id, campaign.name FROM campaign ORDER BY campaign.id","pageSize":1000}

Process finished with exit code 0

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

Would appreciate help on this. Thanks

Google Ads Scripts Forum Advisor

unread,
Nov 1, 2021, 11:09:54 PM11/1/21
to adwords...@googlegroups.com
Hi,

Thanks for reaching out. Harry here, from the Google Ads Scripts Team.

Unfortunately, I won't be able to provide assistance on the issue you are encountering as you are using the Google Apps Script platform so I'd recommend that you reach out to the Google Apps Script Team/Community instead for better assistance. They should be able to provide more insights on what you can adjust in your code. For what it's worth, I suggest Fetching data with UrlFetchApp or use Google Ads Search through Google Ads scripts.

Let me know how I can assist you further.

Thanks,
Google Logo
Harry Cliford Rivera
Google Ads Scripts Team
 


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