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
(Node.js) Shippo Adding MetadataDemonstrates how to add metadata to the tracking request through a POST request. For more information, see https://goshippo.com/docs/tracking/
var os = require('os'); if (os.platform() == 'win32') { if (os.arch() == 'ia32') { var chilkat = require('@chilkat/ck-node21-win-ia32'); } else { var chilkat = require('@chilkat/ck-node21-win64'); } } else if (os.platform() == 'linux') { if (os.arch() == 'arm') { var chilkat = require('@chilkat/ck-node21-arm'); } else if (os.arch() == 'x86') { var chilkat = require('@chilkat/ck-node21-linux32'); } else { var chilkat = require('@chilkat/ck-node21-linux64'); } } else if (os.platform() == 'darwin') { if (os.arch() == 'arm64') { var chilkat = require('@chilkat/ck-node21-mac-m1'); } else { var chilkat = require('@chilkat/ck-node21-macosx'); } } function chilkatExample() { // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. var http = new chilkat.Http(); var success; // 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" var req = new chilkat.HttpRequest(); req.HttpVerb = "POST"; req.Path = "/tracks/"; req.ContentType = "application/x-www-form-urlencoded"; req.AddParam("carrier","shippo"); req.AddParam("tracking_number","SHIPPO_TRANSIT"); req.AddParam("metadata","Order 000123"); req.AddHeader("Authorization","ShippoToken <API_TOKEN>"); // resp: HttpResponse var resp = http.PostUrlEncoded("https://api.goshippo.com/tracks/",req); if (http.LastMethodSuccess == false) { console.log(http.LastErrorText); return; } var sbResponseBody = new chilkat.StringBuilder(); resp.GetBodySb(sbResponseBody); var jResp = new chilkat.JsonObject(); jResp.LoadSb(sbResponseBody); jResp.EmitCompact = false; console.log("Response Body:"); console.log(jResp.Emit()); var respStatusCode = resp.StatusCode; console.log("Response Status Code = " + respStatusCode); if (respStatusCode >= 400) { console.log("Response Header:"); console.log(resp.Header); console.log("Failed."); return; } // 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 var object_created; var object_updated; var object_id; var status; var status_details; var status_date; var substatus; var locationCity; var locationState; var locationZip; var locationCountry; var carrier = jResp.StringOf("carrier"); var tracking_number = jResp.StringOf("tracking_number"); var address_fromCity = jResp.StringOf("address_from.city"); var address_fromState = jResp.StringOf("address_from.state"); var address_fromZip = jResp.StringOf("address_from.zip"); var address_fromCountry = jResp.StringOf("address_from.country"); var address_toCity = jResp.StringOf("address_to.city"); var address_toState = jResp.StringOf("address_to.state"); var address_toZip = jResp.StringOf("address_to.zip"); var address_toCountry = jResp.StringOf("address_to.country"); var eta = jResp.StringOf("eta"); var original_eta = jResp.StringOf("original_eta"); var servicelevelToken = jResp.StringOf("servicelevel.token"); var servicelevelName = jResp.StringOf("servicelevel.name"); var metadata = jResp.StringOf("metadata"); var tracking_statusObject_created = jResp.StringOf("tracking_status.object_created"); var tracking_statusObject_updated = jResp.StringOf("tracking_status.object_updated"); var tracking_statusObject_id = jResp.StringOf("tracking_status.object_id"); var tracking_statusStatus = jResp.StringOf("tracking_status.status"); var tracking_statusStatus_details = jResp.StringOf("tracking_status.status_details"); var tracking_statusStatus_date = jResp.StringOf("tracking_status.status_date"); var tracking_statusSubstatus = jResp.StringOf("tracking_status.substatus"); var tracking_statusLocationCity = jResp.StringOf("tracking_status.location.city"); var tracking_statusLocationState = jResp.StringOf("tracking_status.location.state"); var tracking_statusLocationZip = jResp.StringOf("tracking_status.location.zip"); var tracking_statusLocationCountry = jResp.StringOf("tracking_status.location.country"); var transaction = jResp.StringOf("transaction"); var test = jResp.BoolOf("test"); var i = 0; var count_i = jResp.SizeOfArray("messages"); while (i < count_i) { jResp.I = i; i = i+1; } i = 0; count_i = jResp.SizeOfArray("tracking_history"); while (i < count_i) { jResp.I = i; object_created = jResp.StringOf("tracking_history[i].object_created"); object_updated = jResp.StringOf("tracking_history[i].object_updated"); object_id = jResp.StringOf("tracking_history[i].object_id"); status = jResp.StringOf("tracking_history[i].status"); status_details = jResp.StringOf("tracking_history[i].status_details"); status_date = jResp.StringOf("tracking_history[i].status_date"); substatus = jResp.StringOf("tracking_history[i].substatus"); locationCity = jResp.StringOf("tracking_history[i].location.city"); locationState = jResp.StringOf("tracking_history[i].location.state"); locationZip = jResp.StringOf("tracking_history[i].location.zip"); locationCountry = jResp.StringOf("tracking_history[i].location.country"); i = i+1; } } chilkatExample(); |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.