0
Answered

API node, response object into variable

Vincent DELBEAU 8 years ago updated by anonymous 5 years ago 5

Hi,

I'm using the API node for requesting data from Google Maps API.

But at the Step2[3], the node can't store the response object into variable :


Image 244


I tested the JSON paths with the website : http://jsonpath.com/

I pasted the JSON array into it and tested the JSON path, it's OK ('0' => "my value").


I thought maybe the node can't read the API response but the status is 200 OK, so it could be OK...


Do you have any ideas to help me? :)

Thanks!

Answered

Hi Vincent. Thanks for your note!


The API reply coming for your request is:


{
"error_message": "This service requires an API key.",
"html_attributions": [],
"results": [],
"status": "REQUEST_DENIED"
}

For this particular request, i.e Google maps API, you'll need to provide an API key to use their API. You'll need to consult the Google API documentation as to where exactly to find this API key.


As for the 200 OK coming back as a response, it's due to how Google's API has implemented this particular error scenario. Ideally, Google should not have returned a 200 for an error result.


Please also check the "Open Full Response" link in the popup and see what response is returned by the API. By looking at this response you can see the response returned in your request.

Also, there is one error in the request parameters where the request parameter was starting with "?". We will add a check in the authoring tool so that the character "?" is not accepted in GET requests.

Hope this helps! Thanks again!

Hi Michael,


Thanks for your answer! :)
I know that I need to use API key, I asked mine to Google Developpers website and I got it.
When I write the full URL (with parameters and my Google token) in my browser, that works :



I can see the JSON result.

Indeed, in "Open full Response", I can see :


{  
  "error_message": "This service requires an API key.",
  "html_attributions": [],
  "results": [],
  "status": "REQUEST_DENIED"
}

Maybe the problem comes as you said from the "?" character in the request parameter...

Too bad, I was close ! ^^ I will search another way to get data from JSON without the "?".
Does anyone succeeded to retrieve data from JASON array with the API node ?

Thanks!


+1

Hi Vincent,

I checked your api node. There seems to be following error:

1. '?' in the starting. We automatically add the '?' in the request we send so no need for it to added by you.

2. The requests parameter are separated by & which for you are location=-33.8670522,151.1957362&rankby=distance&types=food&key=YOUR_API_KEY

3. Each request parameter should be entered as a key value pair in the api node. i.e key = value pair. For your case here is the example:


Note: In the tool when you enter a parameter and hit "enter/return" on keyboard a new row comes where you can enter additional parameters.


I have gone ahead and corrected the api requested for you in your tree. It seems to work. Hope this helps.


Let us know in case of any further help.


Regards,

Mitesh

Hi Mitesh, you are awesome :)

Everything works like a charm ;)

Many thanks !