>LOCAL HTTP AS MSXML2.ServerXMLHTTP60 >LOCAL UserLogin AS String >LOCAL UserPassword AS String >LOCAL Guia AS String >LOCAL Reply AS Empty >LOCAL MovementIndex AS Integer >LOCAL Movement AS Object > >* a set of programs to work with JSON, by Marco Plaza >LOCFILE("nfjsonread.prg") > >* an object to handle the web service consumption >m.HTTP = CREATEOBJECT("MSXML2.ServerXMLHTTP.6.0") > >m.UserLogin = "<insert the login, here>" >m.UserPassword = "<and the password, here>" > >m.Guia = INPUTBOX("Insert the order that you want to track", "Guia") >* in production, you'll have to make sure the order identification is properly encoded > >* set the call to the service >m.HTTP.Open("Get", "http://api.urbano.com.pe:8000/api/tracking/e_tracking/?json={%22guia%22%3A%20%22" + m.Guia + "%22,%22docref%22%3A%20%22%22}", .F.) > >m.HTTP.Setrequestheader("Content-type", "application/x-www-form-urlencoded") >m.HTTP.Setrequestheader("user", m.UserLogin) >m.HTTP.Setrequestheader("pass", m.UserPassword) > >* send the request, and wait >* you may send the request asynchronously, this will require recoding >m.HTTP.Send() > >* ingest the returned information, using Marco's function >m.Reply = nfJsonRead(m.HTTP.Responsetext) > >CLEAR > >* look at it >? PADR("Order (guia)", 30, "."), m.Reply.array[1].guia >? PADR("Status (estado)", 30, "."), m.Reply.array[1].estado >? PADR("Date (fecha)", 30, "."), m.Reply.array[1].fecha >? PADR("Hour (hora)", 30, "."), m.Reply.array[1].hora >? PADR("Start date (fecha de ingreso)", 30, "."), m.Reply.array[1].f_ingreso >? PADR("Weight (peso)", 30, "."), m.Reply.array[1].peso >? PADR("Items (piezas)", 30, "."), m.Reply.array[1].piezas >? "Movements (movimientos)" > >FOR m.MovementIndex = 1 TO ALEN(m.Reply.array[1].movimientos) > ? "#",m.MovementIndex > m.Movement = m.Reply.array[1].movimientos[m.MovementIndex] > ? PADR("Status (estado)", 30, "."), m.Movement.estado > ? PADR("Sub-Status (sub-estado)", 30, "."), m.Movement.sub_estado > ? PADR("Date (fecha)", 30, "."), m.Movement.fecha > ? PADR("Hour (hora)", 30, "."), m.Movement.hora >ENDFOR >>
> >Order (guia).................. WYB31912679 >Status (estado)............... ENTREGADO >Date (fecha).................. 24/10/2017 >Hour (hora)................... 17:41 >Start date (fecha de ingreso). 18/10/2017 >Weight (peso)................. 1.26 >Items (piezas)................ 1 >Movements (movimientos) ># 1 >Status (estado)............... SOLICITUD DE SERVICIO >Sub-Status (sub-estado)....... Pick Up (File) >Date (fecha).................. 18/10/2017 >Hour (hora)................... 15:20 ># 2 >Status (estado)............... ADMITIDO EN HUB >Sub-Status (sub-estado)....... Arribo En Origen >Date (fecha).................. 18/10/2017 >Hour (hora)................... 21:55 ># 3 >Status (estado)............... DESPACHADO A DESTINO >Sub-Status (sub-estado)....... Despacho A Destino >Date (fecha).................. 18/10/2017 >Hour (hora)................... 21:57 ># 4 >Status (estado)............... ARRIBADO EN DESTINO >Sub-Status (sub-estado)....... Arribo Agencia (Manual) >Date (fecha).................. 19/10/2017 >Hour (hora)................... 09:25 ># 5 >Status (estado)............... SALIO A RUTA >Sub-Status (sub-estado)....... En Ruta >Date (fecha).................. 20/10/2017 >Hour (hora)................... 00:00 ># 6 >Status (estado)............... VISITADO >Sub-Status (sub-estado)....... Coordinacion Posterior >Date (fecha).................. 20/10/2017 >Hour (hora)................... 06:35 ># 7 >Status (estado)............... SALIO A RUTA >Sub-Status (sub-estado)....... En Ruta >Date (fecha).................. 24/10/2017 >Hour (hora)................... 15:45 ># 8 >Status (estado)............... ENTREGADO >Sub-Status (sub-estado)....... Entrega Efectiva >Date (fecha).................. 24/10/2017 >Hour (hora)................... 17:41 ># 9 >Status (estado)............... POD RENDIDO A ORIGEN >Sub-Status (sub-estado)....... Pod Rendido A Origen >Date (fecha).................. 24/10/2017 >Hour (hora)................... 18:03 >>