Is it possible to get the /route endpoint to return GPX instead of JSON

The website can generate and export a GPX file so that I can upload it to a GPS and do routing (I’m assuming). But I don’t see any documentation on how to query the API and get GPX in return. I did some searching in this forum and came up with a single post (that was never answered) that mentioned some gpx options but I don’t see them in the documentation and I tried them and couldn’t get them to work. Is querying for a GPX route possible?

Oddly, it doesn’t seem to be documented on their official API documentation, but it is available. You just need to change the “type” parameter to be “gpx”. For example:

https://graphhopper.com/api/1//route?point=49.052945%2C-1.464787&point=49.047432%2C-1.44865&locale=en-GB&key=XXXXXXXXXXXXXXXXX&elevation=true&profile=car&type=gpx

You can see the other parameters that manipulate the GPX output format at graphhopper/RouteResource.java at master · graphhopper/graphhopper · GitHub

1 Like

Currently we think about deprecating type=gpx. The reason is that this is a seldom used feature but creating more development work than necessary and client side applications like our GraphHopper Maps can always convert the JSON into a GPX.

Thanks for the help on the undocumented option. I was able to GET the gpx with curl and the url you gave (and my api key), but I couldn’t get it to work with Insomnia using a POST with a custom routing profile. I posted the profile with Content-Type: application/json and specified that I could “Accept: /”, but I couldn’t get it to return GPX that way. Any ideas?

Powered by Discourse