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
(Lianja) 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. loHttp = createobject("CkHttp") // 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" loReq = createobject("CkHttpRequest") loReq.HttpVerb = "POST" loReq.Path = "/tracks/" loReq.ContentType = "application/x-www-form-urlencoded" loReq.AddParam("carrier","shippo") loReq.AddParam("tracking_number","SHIPPO_TRANSIT") loReq.AddParam("metadata","Order 000123") loReq.AddHeader("Authorization","ShippoToken <API_TOKEN>") loResp = loHttp.PostUrlEncoded("https://api.goshippo.com/tracks/",loReq) if (loHttp.LastMethodSuccess = .F.) then ? loHttp.LastErrorText release loHttp release loReq return endif loSbResponseBody = createobject("CkStringBuilder") loResp.GetBodySb(loSbResponseBody) loJResp = createobject("CkJsonObject") loJResp.LoadSb(loSbResponseBody) loJResp.EmitCompact = .F. ? "Response Body:" ? loJResp.Emit() lnRespStatusCode = loResp.StatusCode ? "Response Status Code = " + str(lnRespStatusCode) if (lnRespStatusCode >= 400) then ? "Response Header:" ? loResp.Header ? "Failed." release loResp release loHttp release loReq release loSbResponseBody release loJResp return endif release loResp // 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 lcCarrier = loJResp.StringOf("carrier") lcTracking_number = loJResp.StringOf("tracking_number") lcAddress_fromCity = loJResp.StringOf("address_from.city") lcAddress_fromState = loJResp.StringOf("address_from.state") lcAddress_fromZip = loJResp.StringOf("address_from.zip") lcAddress_fromCountry = loJResp.StringOf("address_from.country") lcAddress_toCity = loJResp.StringOf("address_to.city") lcAddress_toState = loJResp.StringOf("address_to.state") lcAddress_toZip = loJResp.StringOf("address_to.zip") lcAddress_toCountry = loJResp.StringOf("address_to.country") lcEta = loJResp.StringOf("eta") lcOriginal_eta = loJResp.StringOf("original_eta") lcServicelevelToken = loJResp.StringOf("servicelevel.token") lcServicelevelName = loJResp.StringOf("servicelevel.name") lcMetadata = loJResp.StringOf("metadata") lcTracking_statusObject_created = loJResp.StringOf("tracking_status.object_created") lcTracking_statusObject_updated = loJResp.StringOf("tracking_status.object_updated") lcTracking_statusObject_id = loJResp.StringOf("tracking_status.object_id") lcTracking_statusStatus = loJResp.StringOf("tracking_status.status") lcTracking_statusStatus_details = loJResp.StringOf("tracking_status.status_details") lcTracking_statusStatus_date = loJResp.StringOf("tracking_status.status_date") lcTracking_statusSubstatus = loJResp.StringOf("tracking_status.substatus") lcTracking_statusLocationCity = loJResp.StringOf("tracking_status.location.city") lcTracking_statusLocationState = loJResp.StringOf("tracking_status.location.state") lcTracking_statusLocationZip = loJResp.StringOf("tracking_status.location.zip") lcTracking_statusLocationCountry = loJResp.StringOf("tracking_status.location.country") lcTransaction = loJResp.StringOf("transaction") llTest = loJResp.BoolOf("test") i = 0 lnCount_i = loJResp.SizeOfArray("messages") do while i < lnCount_i loJResp.I = i i = i + 1 enddo i = 0 lnCount_i = loJResp.SizeOfArray("tracking_history") do while i < lnCount_i loJResp.I = i lcObject_created = loJResp.StringOf("tracking_history[i].object_created") lcObject_updated = loJResp.StringOf("tracking_history[i].object_updated") lcObject_id = loJResp.StringOf("tracking_history[i].object_id") lcStatus = loJResp.StringOf("tracking_history[i].status") lcStatus_details = loJResp.StringOf("tracking_history[i].status_details") lcStatus_date = loJResp.StringOf("tracking_history[i].status_date") lcSubstatus = loJResp.StringOf("tracking_history[i].substatus") lcLocationCity = loJResp.StringOf("tracking_history[i].location.city") lcLocationState = loJResp.StringOf("tracking_history[i].location.state") lcLocationZip = loJResp.StringOf("tracking_history[i].location.zip") lcLocationCountry = loJResp.StringOf("tracking_history[i].location.country") i = i + 1 enddo release loHttp release loReq release loSbResponseBody release loJResp |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.