0

I am evaluating HERE places APIs. However, the url does return the web page instead of plain JSON as response. Example query:

https://places.cit.api.here.com/places/v1/autosuggest?app_id={YOUR_APP_ID}&app_code{YOUR_APP_CODE}&at=52.5304417,13.4111201&q=rest&pretty

I need the response as simple JSON but can't find any information on the documentation page.

  • In addition to what @zero298 said you might what to try removing the "&pretty" I couldn't find a reference to in the docs but I suspect that could be an issue as it likely influences the output style. – Dan Temkin May 07 '18 at 18:38
  • Thanks Dan. I have already tried playing with various arguments. It doesn't work! – SW Developers May 09 '18 at 06:58

3 Answers3

1

The answer is to add callback parameter to the url. Example:

https://places.cit.api.here.com/places/v1/autosuggest?app_id={YOUR_APP_ID}&app_code{YOUR_APP_CODE}&at=52.5304417,13.4111201&q=rest&pretty&callback=xyz

It is not clear from the documentation. I got this information from HERE support.

1

This is because you were trying the request from your browser address bar, in which case the browser automatically adds Accept: text/html to the request headers⁽¹⁾.

Then, because the Places API has some web helper tool to play with available parameters, it returns html (the Web UI) because Accept: text/html was found in the request headers.

The solution to add callback is more a workaround, since it wraps the response with the value of the callback parameter.

Your initial request was actually valid. If you send it from your program or a REST client like Postman instead of from the browser, you actually get JSON by default, so there was nothing more to do. Of course, you can explicitly send the header Accept: application/json to be on the safe side.

[1] Open the network panel of the browser developer tools to see what is sent.

Michel
  • 26,600
  • 6
  • 64
  • 69
0

You must set the Accept header in order for the service to respond in JSON.

See the example within the documentation here:

curl \
  -X GET \
  -H 'Accept: application/json' \
  --get 'https://places.demo.api.here.com/places/v1/discover/search' \
    --data-urlencode 'at=37.7942,-122.4070' \
    --data-urlencode 'q=restaurant' \
    --data-urlencode 'app_id={YOUR_APP_ID}' \
    --data-urlencode 'app_code={YOUR_APP_CODE}'
zero298
  • 25,467
  • 10
  • 75
  • 100