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
(PowerBuilder) Shippo Adding MetadataDemonstrates how to add metadata to the tracking request through a POST request. For more information, see https://goshippo.com/docs/tracking/
integer li_rc oleobject loo_Http integer li_Success oleobject loo_Req oleobject loo_Resp oleobject loo_SbResponseBody oleobject loo_JResp integer li_RespStatusCode string ls_Object_created string ls_Object_updated string ls_Object_id string ls_Status string ls_Status_details string ls_Status_date string ls_Substatus string ls_LocationCity string ls_LocationState string ls_LocationZip string ls_LocationCountry string ls_Carrier string ls_Tracking_number string ls_Address_fromCity string ls_Address_fromState string ls_Address_fromZip string ls_Address_fromCountry string ls_Address_toCity string ls_Address_toState string ls_Address_toZip string ls_Address_toCountry string ls_Eta string ls_Original_eta string ls_ServicelevelToken string ls_ServicelevelName string ls_Metadata string ls_Tracking_statusObject_created string ls_Tracking_statusObject_updated string ls_Tracking_statusObject_id string ls_Tracking_statusStatus string ls_Tracking_statusStatus_details string ls_Tracking_statusStatus_date string ls_Tracking_statusSubstatus string ls_Tracking_statusLocationCity string ls_Tracking_statusLocationState string ls_Tracking_statusLocationZip string ls_Tracking_statusLocationCountry string ls_Transaction integer li_Test integer i integer li_Count_i // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. loo_Http = create oleobject // Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0 li_rc = loo_Http.ConnectToNewObject("Chilkat.Http") if li_rc < 0 then destroy loo_Http MessageBox("Error","Connecting to COM object failed") return end if // 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" loo_Req = create oleobject // Use "Chilkat_9_5_0.HttpRequest" for versions of Chilkat < 10.0.0 li_rc = loo_Req.ConnectToNewObject("Chilkat.HttpRequest") loo_Req.HttpVerb = "POST" loo_Req.Path = "/tracks/" loo_Req.ContentType = "application/x-www-form-urlencoded" loo_Req.AddParam("carrier","shippo") loo_Req.AddParam("tracking_number","SHIPPO_TRANSIT") loo_Req.AddParam("metadata","Order 000123") loo_Req.AddHeader("Authorization","ShippoToken <API_TOKEN>") loo_Resp = loo_Http.PostUrlEncoded("https://api.goshippo.com/tracks/",loo_Req) if loo_Http.LastMethodSuccess = 0 then Write-Debug loo_Http.LastErrorText destroy loo_Http destroy loo_Req return end if loo_SbResponseBody = create oleobject // Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0 li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat.StringBuilder") loo_Resp.GetBodySb(loo_SbResponseBody) loo_JResp = create oleobject // Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 li_rc = loo_JResp.ConnectToNewObject("Chilkat.JsonObject") loo_JResp.LoadSb(loo_SbResponseBody) loo_JResp.EmitCompact = 0 Write-Debug "Response Body:" Write-Debug loo_JResp.Emit() li_RespStatusCode = loo_Resp.StatusCode Write-Debug "Response Status Code = " + string(li_RespStatusCode) if li_RespStatusCode >= 400 then Write-Debug "Response Header:" Write-Debug loo_Resp.Header Write-Debug "Failed." destroy loo_Resp destroy loo_Http destroy loo_Req destroy loo_SbResponseBody destroy loo_JResp return end if destroy loo_Resp // 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 ls_Carrier = loo_JResp.StringOf("carrier") ls_Tracking_number = loo_JResp.StringOf("tracking_number") ls_Address_fromCity = loo_JResp.StringOf("address_from.city") ls_Address_fromState = loo_JResp.StringOf("address_from.state") ls_Address_fromZip = loo_JResp.StringOf("address_from.zip") ls_Address_fromCountry = loo_JResp.StringOf("address_from.country") ls_Address_toCity = loo_JResp.StringOf("address_to.city") ls_Address_toState = loo_JResp.StringOf("address_to.state") ls_Address_toZip = loo_JResp.StringOf("address_to.zip") ls_Address_toCountry = loo_JResp.StringOf("address_to.country") ls_Eta = loo_JResp.StringOf("eta") ls_Original_eta = loo_JResp.StringOf("original_eta") ls_ServicelevelToken = loo_JResp.StringOf("servicelevel.token") ls_ServicelevelName = loo_JResp.StringOf("servicelevel.name") ls_Metadata = loo_JResp.StringOf("metadata") ls_Tracking_statusObject_created = loo_JResp.StringOf("tracking_status.object_created") ls_Tracking_statusObject_updated = loo_JResp.StringOf("tracking_status.object_updated") ls_Tracking_statusObject_id = loo_JResp.StringOf("tracking_status.object_id") ls_Tracking_statusStatus = loo_JResp.StringOf("tracking_status.status") ls_Tracking_statusStatus_details = loo_JResp.StringOf("tracking_status.status_details") ls_Tracking_statusStatus_date = loo_JResp.StringOf("tracking_status.status_date") ls_Tracking_statusSubstatus = loo_JResp.StringOf("tracking_status.substatus") ls_Tracking_statusLocationCity = loo_JResp.StringOf("tracking_status.location.city") ls_Tracking_statusLocationState = loo_JResp.StringOf("tracking_status.location.state") ls_Tracking_statusLocationZip = loo_JResp.StringOf("tracking_status.location.zip") ls_Tracking_statusLocationCountry = loo_JResp.StringOf("tracking_status.location.country") ls_Transaction = loo_JResp.StringOf("transaction") li_Test = loo_JResp.BoolOf("test") i = 0 li_Count_i = loo_JResp.SizeOfArray("messages") do while i < li_Count_i loo_JResp.I = i i = i + 1 loop i = 0 li_Count_i = loo_JResp.SizeOfArray("tracking_history") do while i < li_Count_i loo_JResp.I = i ls_Object_created = loo_JResp.StringOf("tracking_history[i].object_created") ls_Object_updated = loo_JResp.StringOf("tracking_history[i].object_updated") ls_Object_id = loo_JResp.StringOf("tracking_history[i].object_id") ls_Status = loo_JResp.StringOf("tracking_history[i].status") ls_Status_details = loo_JResp.StringOf("tracking_history[i].status_details") ls_Status_date = loo_JResp.StringOf("tracking_history[i].status_date") ls_Substatus = loo_JResp.StringOf("tracking_history[i].substatus") ls_LocationCity = loo_JResp.StringOf("tracking_history[i].location.city") ls_LocationState = loo_JResp.StringOf("tracking_history[i].location.state") ls_LocationZip = loo_JResp.StringOf("tracking_history[i].location.zip") ls_LocationCountry = loo_JResp.StringOf("tracking_history[i].location.country") i = i + 1 loop destroy loo_Http destroy loo_Req destroy loo_SbResponseBody destroy loo_JResp |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.