Codeless API call to Google API - keyInvalid Usage Limits

Hi

I’m using Codeless with an APIService to call a google search api using the http block.

When I invoke the call, I am getting the following error:
{
“code”: 0,
“message”: “{“error”:{“errors”:[{“domain”:“usageLimits”,“reason”:“keyInvalid”,“message”:“Bad Request”}],“code”:400,“message”:“Bad Request”}}”
}

When I use the cURL statement generated by Backendless, I get the same error as above:
curl -X “GET” “https://api.backendless.com/A603AF06-3DDD-6D47-FF01-D559C4DF9300/2F5D244B-421F-7DF6-FF7C-89DE2065ED00/services/GoogleSearch/getGoogleSearch?q=“window%20suppliers”&cx=“004622423927607956040%3Aaqbe3g8agpg”&key=“AIzaSyDHSauVwSIwVs5boAuEgnXZJL4DcitzoKo”
-H ‘Content-Type: application/json’
-H ‘Accept: application/json’

I know that the API key I’m using is valid as the request to the google api directly in cURL works fine and returns the JSON from Google.

When I strip the %22 from the Backendless cURL command, it does work in cURL :
curl -X “GET” “https://api.backendless.com/A603AF06-3DDD-6D47-FF01-D559C4DF9300/2F5D244B-421F-7DF6-FF7C-89DE2065ED00/services/GoogleSearch/getGoogleSearch?q=window%20suppliers&cx=004622423927607956040%3Aaqbe3g8agpg&key=AIzaSyDHSauVwSIwVs5boAuEgnXZJL4DcitzoKo
-H ‘Content-Type: application/json’
-H ‘Accept: application/json’

Can you please explain what I might be doing wrong ?

Thanks
Paul

Hi Paul

“Request Query Params” block is an object which contains unparsed query params, that’s the reason why you are getting an error from google api.
Instead, you should add a “Create Object” block and set there all the parameters what you need: “q”, “cx”, “key” and etc…

replace this block:
Codeless%20-%20BL%20-%20aa11aa%20-%20Backendless%202018-11-14%2014-51-09

with this:
Codeless%20-%20BL%20-%20aa11aa%20-%20Backendless%202018-11-14%2014-52-19

Thanks, Vlad

Thank you! That worked.

The only thing is I can’t see method argument’s for context blocks for the other parameters I invoke the call with.

Is that the wrong pattern ?

Thanks
Paul

There are two ways to get others parameters in the Codeless Editor:

  1. declare it in API Services section and context blocks will be there for the arguments
  2. or use it dynamically, but before use it convert it from String using “Convert to Object” block

Excellent. Thank you !