Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(AutoIt) Shippo Adding MetadataDemonstrates how to add metadata to the tracking request through a POST request. For more information, see https://goshippo.com/docs/tracking/
; This example assumes the Chilkat API to have been previously unlocked. ; See Global Unlock Sample for sample code. $oHttp = ObjCreate("Chilkat.Http") Local $bSuccess ; Implements the following CURL command: ; curl https://api.goshippo.com/tracks/ \ ; -H "Authorization: ShippoToken <API_TOKEN>" \ ; -d carrier="shippo" \ ; -d tracking_number="SHIPPO_TRANSIT" \ ; -d metadata="Order 000123" $oReq = ObjCreate("Chilkat.HttpRequest") $oReq.HttpVerb = "POST" $oReq.Path = "/tracks/" $oReq.ContentType = "application/x-www-form-urlencoded" $oReq.AddParam "carrier","shippo" $oReq.AddParam "tracking_number","SHIPPO_TRANSIT" $oReq.AddParam "metadata","Order 000123" $oReq.AddHeader "Authorization","ShippoToken <API_TOKEN>" Local $oResp = $oHttp.PostUrlEncoded("https://api.goshippo.com/tracks/",$oReq) If ($oHttp.LastMethodSuccess = False) Then ConsoleWrite($oHttp.LastErrorText & @CRLF) Exit EndIf $oSbResponseBody = ObjCreate("Chilkat.StringBuilder") $oResp.GetBodySb($oSbResponseBody) $oJResp = ObjCreate("Chilkat.JsonObject") $oJResp.LoadSb($oSbResponseBody) $oJResp.EmitCompact = False ConsoleWrite("Response Body:" & @CRLF) ConsoleWrite($oJResp.Emit() & @CRLF) Local $iRespStatusCode = $oResp.StatusCode ConsoleWrite("Response Status Code = " & $iRespStatusCode & @CRLF) If ($iRespStatusCode >= 400) Then ConsoleWrite("Response Header:" & @CRLF) ConsoleWrite($oResp.Header & @CRLF) ConsoleWrite("Failed." & @CRLF) Exit EndIf ; Sample JSON response: ; (Sample code for parsing the JSON response is shown below) ; { ; "messages": [ ; ], ; "carrier": "shippo", ; "tracking_number": "SHIPPO_TRANSIT", ; "address_from": { ; "city": "San Francisco", ; "state": "CA", ; "zip": "94103", ; "country": "US" ; }, ; "address_to": { ; "city": "Chicago", ; "state": "IL", ; "zip": "60611", ; "country": "US" ; }, ; "eta": "2019-07-07T17:07:44.989Z", ; "original_eta": "2019-07-07T17:07:44.989Z", ; "servicelevel": { ; "token": "shippo_priority", ; "name": "Priority Mail" ; }, ; "metadata": "Shippo test tracking", ; "tracking_status": { ; "object_created": "2019-07-04T17:07:45.003Z", ; "object_updated": null, ; "object_id": "ee35fb56f5d04021b36168abedc04573", ; "status": "TRANSIT", ; "status_details": "Your shipment has departed from the origin.", ; "status_date": "2019-07-03T15:02:45.003Z", ; "substatus": null, ; "location": { ; "city": "San Francisco", ; "state": "CA", ; "zip": "94103", ; "country": "US" ; } ; }, ; "tracking_history": [ ; { ; "object_created": "2019-07-04T17:07:45.005Z", ; "object_updated": null, ; "object_id": "2121a59f53ed42e0ae0436f636179156", ; "status": "UNKNOWN", ; "status_details": "The carrier has received the electronic shipment information.", ; "status_date": "2019-07-02T12:57:45.005Z", ; "substatus": null, ; "location": { ; "city": "San Francisco", ; "state": "CA", ; "zip": "94103", ; "country": "US" ; } ; }, ; { ; "object_created": "2019-07-04T17:07:45.005Z", ; "object_updated": null, ; "object_id": "06f949db1a8245beaa28df264b368a76", ; "status": "TRANSIT", ; "status_details": "Your shipment has departed from the origin.", ; "status_date": "2019-07-03T15:02:45.005Z", ; "substatus": null, ; "location": { ; "city": "San Francisco", ; "state": "CA", ; "zip": "94103", ; "country": "US" ; } ; } ; ], ; "transaction": null, ; "test": true ; } ; Sample code for parsing the JSON response... ; Use the following online tool to generate parsing code from sample JSON: ; Generate Parsing Code from JSON Local $sObject_created Local $sObject_updated Local $sObject_id Local $status Local $status_details Local $status_date Local $substatus Local $sLocationCity Local $sLocationState Local $sLocationZip Local $sLocationCountry Local $sCarrier = $oJResp.StringOf("carrier") Local $sTracking_number = $oJResp.StringOf("tracking_number") Local $sAddress_fromCity = $oJResp.StringOf("address_from.city") Local $sAddress_fromState = $oJResp.StringOf("address_from.state") Local $sAddress_fromZip = $oJResp.StringOf("address_from.zip") Local $sAddress_fromCountry = $oJResp.StringOf("address_from.country") Local $sAddress_toCity = $oJResp.StringOf("address_to.city") Local $sAddress_toState = $oJResp.StringOf("address_to.state") Local $sAddress_toZip = $oJResp.StringOf("address_to.zip") Local $sAddress_toCountry = $oJResp.StringOf("address_to.country") Local $sEta = $oJResp.StringOf("eta") Local $sOriginal_eta = $oJResp.StringOf("original_eta") Local $servicelevelToken = $oJResp.StringOf("servicelevel.token") Local $servicelevelName = $oJResp.StringOf("servicelevel.name") Local $sMetadata = $oJResp.StringOf("metadata") Local $sTracking_statusObject_created = $oJResp.StringOf("tracking_status.object_created") Local $sTracking_statusObject_updated = $oJResp.StringOf("tracking_status.object_updated") Local $sTracking_statusObject_id = $oJResp.StringOf("tracking_status.object_id") Local $sTracking_statusStatus = $oJResp.StringOf("tracking_status.status") Local $sTracking_statusStatus_details = $oJResp.StringOf("tracking_status.status_details") Local $sTracking_statusStatus_date = $oJResp.StringOf("tracking_status.status_date") Local $sTracking_statusSubstatus = $oJResp.StringOf("tracking_status.substatus") Local $sTracking_statusLocationCity = $oJResp.StringOf("tracking_status.location.city") Local $sTracking_statusLocationState = $oJResp.StringOf("tracking_status.location.state") Local $sTracking_statusLocationZip = $oJResp.StringOf("tracking_status.location.zip") Local $sTracking_statusLocationCountry = $oJResp.StringOf("tracking_status.location.country") Local $sTransaction = $oJResp.StringOf("transaction") Local $bTest = $oJResp.BoolOf("test") Local $i = 0 Local $iCount_i = $oJResp.SizeOfArray("messages") While $i < $iCount_i $oJResp.I = $i $i = $i + 1 Wend $i = 0 $iCount_i = $oJResp.SizeOfArray("tracking_history") While $i < $iCount_i $oJResp.I = $i $sObject_created = $oJResp.StringOf("tracking_history[i].object_created") $sObject_updated = $oJResp.StringOf("tracking_history[i].object_updated") $sObject_id = $oJResp.StringOf("tracking_history[i].object_id") $status = $oJResp.StringOf("tracking_history[i].status") $status_details = $oJResp.StringOf("tracking_history[i].status_details") $status_date = $oJResp.StringOf("tracking_history[i].status_date") $substatus = $oJResp.StringOf("tracking_history[i].substatus") $sLocationCity = $oJResp.StringOf("tracking_history[i].location.city") $sLocationState = $oJResp.StringOf("tracking_history[i].location.state") $sLocationZip = $oJResp.StringOf("tracking_history[i].location.zip") $sLocationCountry = $oJResp.StringOf("tracking_history[i].location.country") $i = $i + 1 Wend |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.