Search code examples
apiresponsehere-apihere-maps-rest

HERE API request returns view instead of JSON


I'm trying to use the Places (Search) API (or any HERE API for that matter) for the first time. I tried the example in this page and got this page as a response:

https://places.cit.api.here.com/places/v1/browse?app_id=YOUR-APP-ID&app_code=YOUR-APP-CODE&in=52.521,13.3807;r=2000&cat=petrol-station&pretty this view

I don't know what I'm missing here but, I expected to get a plain JSON/XML response (orange rectangle), like this example of the Routing (Isoline) API which outputs this to the browser:

https://isoline.route.cit.api.here.com/routing/7.2/calculateisoline.json?mode=fastest;car;traffic:disabled&jsonAttributes=1&rangetype=time&start=34.603565,-98.3959&app_id=YOUR-APP-ID&app_code=YOUR-APP-CODE&range=1800

enter image description here

this way I could consume the service using the JSON/XML output.

I already tried both examples above in my Spring (JAVA) app and the second one works as expected, while the first one throws error (as expected).

HERE API newbie here, help appreciated.

PS: this project app of mine is just about finding nearby POIs (e.g: gyms, coffee shops, pharmacies, cinemas, etc). So, any suggestions on what API is best to go with for this, also very appreciated.


Solution

  • I don't know the HERE api but from having a quick look it seems they generate your results depending on the Accept header in your http request.

    By default my chrome sends this accept header:

    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
    

    If I use Postman to send the request without any Accept header or Accept: application/json it returns the json results.

    Accept-application-json

    If I add an Accept: text/html header to the request in Postman it sends me the PlayPen in html.

    Accept-text-html

    You can also see in their documentation that they use the appropriate Accept: application/json

    enter image description here

    I suggest you use Postman to test and play with the API's.