Recently, I had to implement Mondial Relay on a website, to allow clients to choose the relay of their choice. We had 2 options:

  • The SOAP API, which was not really an option: it was a bunch of awful XML (I do not really like SOAP) and it required a private key to authenticate the request, not the kind of thing we can put on an SPA.
  • The jQuery Widget: I can accept jQuery, but it is more difficult when said jQuery is an out of date version, the widget not being compatible with jQuery 3, and needed to be included globally ☹. Furthermore, not all options was available through their widget, like searching by GPS coordinate, which is what I want to do.

Part 1: Find the Widget API

Okay, so obviously, the widget did not need a private key, so it was not using the SOAP API. In fact, it was using an other API which returned JSON. Of course, that API was not documented.

Fortunately, using the network pane of the devtools, we managed to find the call to the API. Easy.

Part 2: Call the widget API

Next we need to call the API. We copy the URL used by the widget in the neat fetch function and… we get a CORS error. They did not allow CORS on an API built to be used by a browser widget. Fallback to JSONP then, I too, do like to travel in the past.

Part 3 : Using the API

We found the URL, we found how to get a result, now we need to use it. By getting rid of most of the URL, we can find the query string parameters we want: Latitude and Longitude. Getting GPS coordinate using google API and… no relay found.

Okay, we need to take back the first reponse we got.

{
  "Adresse1": "5 RUE CHAPON",
  "Adresse2": null,
  "Available": true,
  "CP": "75003",
  "ID": "001726",
  "Lat": "48,8628526",
  "Long": "2,3570854",
  "Nature": "1",
  "Nom": "LAND OR",
  "Pays": "FR",
  "Photo": null,
  "Ville": "PARIS"
}

And then the question: why anybody on earth would put latitude and longitude in a string, with comma to separate decimals? Well, they do. So let’s format it there way. Still not working, because in addition, this API only accept exactly 7 decimal digits, no less, no more. Otherwise, you will get an error that say that no relays were found. Logic.

And then… everything work! We finally get the correct result.

Conclusion

The fact is, what we did here is a terrible solution: we are using an undocumented, unversioned API that can break at any time, but in our case, it was the best solution.

If ever you want to user this API too, here is a small documentation:

Endpoint: https://widget.mondialrelay.com/parcelshop-picker/v4_0/services/parcelshop-picker.svc/SearchPR

Query parameters:

Field Name Description
method The JSONP callback
Brand The brand given to you by Mondial Relay
Country The country in which you want to perform the search
PostCode Postal code for your research, not used if you use latitude and longitude
ColLivMod Used to filter the relay, check the widget documentation for this one
Weight Weight of the package
NbResults Number of resultats that you will get
SearchDelay Number of day until the delivery
SearchFar Radius of the search
Latitude & Longitude GPS coordinate, use a comma as decimal separator and exactly 7 decimal digits
_ (underscore) The timestamp, a simple Date.now() will do

The response is pretty straightforward, you should be able to handle it correctly. May the force be with you.