1

Assigning orders and creating routes via API

Topic: Assigning orders and creating routes via API

Hi,

I am helping my client integrate their internal systems with Logistics. On Logistics web UI, they can do the following:
1.    In the Planning section, they created orders

2.    Next, they chose an available unit and assigned the orders to the unit. The order then showed up in the Route section.



However, what the client really wants is to achieve the above steps via API.
1.    For step 1, they did that with https://hst-api.wialon.com/wialon/ajax. … er/update. It created orders and they showed up on the Logistics web UI.
2.    For step 2, they used the following API call
https://hst-api.wialon.com/wialon/ajax. … mp;params=
{
"itemId": 17640076,
"id": 15, "u":22191249,
"callMode": "assign"
}&sid=025b5aeaa7d8b4f718e0f8c9a9f2a110

But when they went back to Logistics Web UI. The order disappeared from both the Planning section and the Routes section. They compared the difference between these two scenarios (UI vs API) using the Search API to retrieve all the orders. When it is done on the web UI, the following data was returned as part of the search result.

"order_routes":{"1":{"id":1,"n":"KNF Tag 1","uid":1609775018901,"f":1,"exp":359940,"ord":[267576462540904],"fu":[],"st":
{"nid":40,"lid":0,"u":22191249,"s":1,"sf":0,"st":0, "mint":1609774995,"maxt":1609775595}}}
Order field u was not updated. Its value was still 0.

When it is done using the order/update API, only the u property of the order was updated to the unit ID, no order_routes was created in this case.



So, I am wondering what API calls should be made to achieve the same result as the two steps done on the web UI (create orders and assign them to units and create routes).

I tried using the following API.

https://hst-api.wialon.com/wialon/ajax. … p;params={
"itemId": 17640076,
"orders": [{
"id": 44,
"f": 1,
"u":22191249,
"callMode": "assign"
}],
"callMode": "create"
}&sid=02eb32a18d5f567b817348ffe62c3234

But it gave me and error 4. The 44 is the id of a newly created order. It hasn’t been assigned to any unit.

{
    "error": 4,
    "reason": "VALIDATE_PARAMS_ERROR: {id: long}"
}

Any help is appreciated.

Jeff

2

Assigning orders and creating routes via API

Re: Assigning orders and creating routes via API

Hello Jeff!
to create an order, you can use this API:
https://sdk.wialon.com/wiki/en/sidebar/ … der/update
Create an order with callMode:“create”

Example:

svc=order/update&params={"uid":0,"id":0,"n":"2 копия","p": {"uid":0,"id":0,"n":"Delivery","p":{"n":"Tony","p":"","p2":"","e":"","a":"vulica Matusieviča 7, Minsk, Belarus","v":10,"w":45.3592,"c":100,"d":"Hi!","ut":600,"t":"","r":null,"cid":"","ntf":0,"pr":0,"tags":[]},"f":1,"tf":1610391600,"tt":1610395140,"r":100,"y":53.915258958120475,"x":27.486151214976196,"u":"","s":0,"trt":120,"cf":{"Номер накладной":"","Поставщик":"","Тип груза":""},"itemId":21126416,"callMode":"create"}

I will describe the logic of creating a route:
- first, we optimize the route ( we get the track and arrival time for orders)
- we record the received data into orders
- save the route

callMode:«assign» - this is an outdated way of creating, better not to use it

Optimization:

In order to use optimization while executing orders use order/optimize:
https://sdk.wialon.com/wiki/en/sidebar/ … r/optimize

Example

svc=order/optimize&params={"itemId":21126416,"orders":[{"y":53.8986740112,"x":27.5098991394,"tf":1610348400,"n":"8","tt":1610391600,"f":0,"r":100,"p":{"ut":300,"rep":true,"w":0.0447,"v":10}},{"y":53.9037322998,"x":27.5195178986,"tf":1610348400,"n":"9","tt":1610391600,"f":0,"r":100,"p":{"ut":300,"rep":true,"w":0.0447,"v":10}},{"y":53.9091911316,"x":27.5244064331,"tf":1610348400,"n":"44","tt":1610391600,"f":0,"r":100,"p":{"ut":300,"rep":true,"w":0.0447,"v":10}}],"warehouses":[],"flags":131,"units":[21131933],"gis":{"addPoints":1,"provider":2,"speed":360,"cityJams":0.7,"countryJams":1,"mode":"driving","departure_time":1}}

Example of creating a route:

https://sdk.wialon.com/wiki/en/sidebar/ … ute_update

Example:

https://hst-api.wialon.com/wialon/ajax.html?svc=order/route_update&sid=<SID>&params={{"itemId":21126416,"orders":[{"uid":0,"id":0,"n":"8","p":{"n":"","p":"","p2":"","e":"","a":"ул. Харьковская 61, Минск, Беларусь","v":10,"w":0.0447,"c":0,"ut":300,"t":"","d":"","uic":"","cid":"","r":{"vt":1610360809,"ndt":1200,"id":1610359357951,"i":0,"m":0,"t":0},"aff":"","z":"","ntf":0,"cm":"","pr":0,"tags":[],"rep":true},"f":64,"tf":1610348400,"tt":1610391600,"r":100,"y":53.8986740112,"x":27.5098991394,"u":21131933,"s":0,"sf":0,"trt":120,"st":1606825424,"cnm":0,"rp":"","ej":{},"cf":{"Factura":"","Proveedor":"","Tipo de carga":"","frgrtgrt":"","fvfv":"","ppppoooo":"","tgtttt":"","Номер накладной":"","Поставщик":"","Тип груза":"","Тип груза ":"","авмвамавм":"","куикуикуик":"","№ паллета":""},"callMode":"create"},{"uid":0,"id":0,"n":"9","p":{"n":"","p":"","p2":"","e":"","a":"ул. 3-го сентября 1а, Минск, Беларусь","v":10,"w":0.0447,"c":0,"ut":300,"t":"","d":"","uic":"","cid":"","r":{"vt":1610361643,"ndt":1200,"id":1610359357951,"i":1,"m":1132,"t":834},"aff":"","z":"","ntf":0,"cm":"","pr":0,"tags":[],"rep":true},"f":64,"tf":1610348400,"tt":1610391600,"r":100,"y":53.9037322998,"x":27.5195178986,"u":21131933,"s":0,"sf":0,"trt":120,"st":1606825427,"cnm":0,"rp":"oa~gIi_|fDYZGSq@x@_@}AQkAY_Co@mF_A_H}AuLk@uCyBcIwF~CmBbA}AdAQqAiBgL","ej":{},"cf":{"Factura":"","Proveedor":"","Tipo de carga":"","frgrtgrt":"","fvfv":"","ppppoooo":"","tgtttt":"","Номер накладной":"","Поставщик":"","Тип груза":"","Тип груза ":"","авмвамавм":"","куикуикуик":"","№ паллета":""},"callMode":"create"},{"uid":0,"id":0,"n":"44","p":{"n":"","p":"","p2":"","e":"","a":"просп. Машерова 10, Минск, Беларусь","v":10,"w":0.0447,"c":0,"ut":300,"t":"","d":"","uic":"","cid":"","r":{"vt":1610362423,"ndt":1200,"id":1610359357951,"i":2,"m":864,"t":780},"aff":"","z":"","ntf":0,"cm":"","pr":0,"tags":[],"rep":true},"f":0,"tf":1610348400,"tt":1610391600,"r":100,"y":53.9091911316,"x":27.5244064331,"u":21131933,"s":0,"sf":0,"trt":1200,"st":1604557324,"cnm":0,"rp":"od_hIs{}fDi@gDGe@OsAUOIGgBi@iASoAUq@OBiAA[?i@ZuGBcACu@Kq@kAr@eAf@UJWJ[HQD_@H]Be@Dm@?YAgAIc@IYGo@YWM","ej":{},"cf":{"Provider name":"","Поставщик":"","Тип груза":"","№ паллета":""},"callMode":"create"}],"uid":1610359357951,"callMode":"create","exp":76277,"f":0,"n":"Сourier "}}],"flags":0}

here is an example, it has:
- optimization
- filling in the arrival time, track
- saving the route

you need to set SID, RES_ID, UNITS_ID
https://codesandbox.io/embed/relaxed-sunset-glf8d

I hope you will find this information useful.

Best regards,

Anton Voitenko

3

Assigning orders and creating routes via API

(edited by stal 11/01/2021 17:05:21)

Re: Assigning orders and creating routes via API

Good evening.
In addition to Anton's answer, using callMode:assign is a deprecated method for creating routes and cannot currently be used for this.
The order/route_update method also does not support this callMode.
To use order/route_update you must specify the required parameter "uid" (or "id" if this is a change to an existing route). Currently uid must be generated on client-side. It must be unique numberic ID, for example timestamp with ms: "uid":1610370226382.
In the "orders" parameter, the method expects collection of full JSON-s of orders with some additional parameters inside each element:
callMode=update (or create)
"r" inside of "p",  with some info about route e.g. "r":{"id":1610370226382 /*-route uid*/,"vt":1610370218 /*-estimated arrival time*/,"i":0/*sequential number*/,"m":0/*mileage from prev. order*/,"t":0/*time from prev. order*/}

4

Assigning orders and creating routes via API

Re: Assigning orders and creating routes via API

Thanks Aton and stal for your help. I am able to create a route with an order now.

Jeff