Nominatim API returns results in browser but empty list when called from Spring Boot

When querying OpenStreetMap’s Nominatim API, large cities work fine from Spring Boot, but smaller towns return an empty response, even though the same URL works in a browser.

Have you got any examples you can provide to us? If you can give us the queries you’re using, that might help others provide assistance.

1 Like

The query I’m using is for example:

https://nominatim.openstreetmap.org/search?format=json&limit=1&countrycodes=hr&q=Hodošan

When I open this URL directly in the browser, I get a valid JSON response with latitude and longitude.

However, when I perform the same request from Spring Boot using RestTemplate (same URL, same query parameters, UTF-8 encoded, custom User-Agent set), the response body is an empty array [] with HTTP 200.

One thing to look out for the accept-language parameter. The default is ‘en’ (english). A browser sets it to the language settings of your operating system, likely Croatian. Try setting &accept-language=hr in your script.

On Nominatim Demo click ‘Advanced options’ and the last line shows “your browser is using”.

I’ve already tried that.

In my Spring Boot request I explicitly set the headers to match what the browser sends, including Accept-Language and User-Agent.

have you tried using wireshark/other similar tool to inspect requests made and their responses to look for differences?

I ran the request against all Nominatim servers individually, results look the same. So I think we can rule that the requests are routed to different servers (based on geo-ip)

hard to guess without seeing code (and it is often hard also with it) but I bet that either queries in fact are not the same or there is some bug in Spring Boot with processing responses

1 Like

My guess here would be that encoding is going wrong. Is it really larger cities that work? Or is it rather that those cities work that only consist of simple ascii characters without diacritics? Will your Spring Boot Code find something for “Hodosan” (as opposed to “Hodošan”)?