Reputation: 21
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.
Upvotes: 0
Views: 351
Reputation: 28289
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.
Upvotes: 1
Reputation: 21
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.
Upvotes: 1
Reputation: 26878
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}'
Upvotes: 0