Enhancements


API for distance calculation


Context: Currently, we do not have any APIs exposed to calculate distance between shipping address and the fulfillment center address. Such an API would be consumed for use cases such as the “order allocation based on distance” by the Order Management System.


Solution: A new API has been exposed to calculate the distance based on the following inputs:

  • Origin Latitude

  • Origin Longitude

  • Destination Latitude

  • Destination Longitude

  • The API will return the respective distance chosen in ‘Control Panel -> Settings -> Application Settings -> Store Settings’

    • Linear Distance OR

    • Driving Distance

  • Validation error will be thrown if ‘Default’ is chosen in ‘Store Settings’ instead of Linear Distance or Driving Distance.


API: /v1/distance/{merchantid}/

 

Request sample:

 

[

{

"origin":{

"latitude":51.5007,

"longitude":0.1246

},

"destination":{

"latitude":40.6892,

"longitude":74.0445

}

},

{

"origin":{

"latitude":12,

"longitude":123

},

"destination":{

"latitude":12,

"longitude":32

}

}

]

 

Response sample:

 

{

"entity": [

{

"origin": {

"latitude": 51.5007,

"longitude": 0.1246

},

"destination": {

"latitude": 40.6892,

"longitude": 74.0445

},

"distance": {

"text": "5574.840456848555 km",

"value": 5574840

},

"duration": null

},

{

"origin": {

"latitude": 12,

"longitude": 123

},

"destination": {

"latitude": 12,

"longitude": 32

},

"distance": {

"text": "9838.505493338416 km",

"value": 9838505

},

"duration": null

}

],

"warnings": []

}