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
(Unicode C++) Shippo Adding MetadataDemonstrates how to add metadata to the tracking request through a POST request. For more information, see https://goshippo.com/docs/tracking/
#include <CkHttpW.h> #include <CkHttpRequestW.h> #include <CkHttpResponseW.h> #include <CkStringBuilderW.h> #include <CkJsonObjectW.h> void ChilkatSample(void) { // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. CkHttpW http; bool 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" CkHttpRequestW req; req.put_HttpVerb(L"POST"); req.put_Path(L"/tracks/"); req.put_ContentType(L"application/x-www-form-urlencoded"); req.AddParam(L"carrier",L"shippo"); req.AddParam(L"tracking_number",L"SHIPPO_TRANSIT"); req.AddParam(L"metadata",L"Order 000123"); req.AddHeader(L"Authorization",L"ShippoToken <API_TOKEN>"); CkHttpResponseW *resp = http.PostUrlEncoded(L"https://api.goshippo.com/tracks/",req); if (http.get_LastMethodSuccess() == false) { wprintf(L"%s\n",http.lastErrorText()); return; } CkStringBuilderW sbResponseBody; resp->GetBodySb(sbResponseBody); CkJsonObjectW jResp; jResp.LoadSb(sbResponseBody); jResp.put_EmitCompact(false); wprintf(L"Response Body:\n"); wprintf(L"%s\n",jResp.emit()); int respStatusCode = resp->get_StatusCode(); wprintf(L"Response Status Code = %d\n",respStatusCode); if (respStatusCode >= 400) { wprintf(L"Response Header:\n"); wprintf(L"%s\n",resp->header()); wprintf(L"Failed.\n"); delete resp; return; } delete 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 // Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat. // See this example explaining how this memory should be used: const char * functions. const wchar_t *object_created = 0; const wchar_t *object_updated = 0; const wchar_t *object_id = 0; const wchar_t *status = 0; const wchar_t *status_details = 0; const wchar_t *status_date = 0; const wchar_t *substatus = 0; const wchar_t *locationCity = 0; const wchar_t *locationState = 0; const wchar_t *locationZip = 0; const wchar_t *locationCountry = 0; const wchar_t *carrier = jResp.stringOf(L"carrier"); const wchar_t *tracking_number = jResp.stringOf(L"tracking_number"); const wchar_t *address_fromCity = jResp.stringOf(L"address_from.city"); const wchar_t *address_fromState = jResp.stringOf(L"address_from.state"); const wchar_t *address_fromZip = jResp.stringOf(L"address_from.zip"); const wchar_t *address_fromCountry = jResp.stringOf(L"address_from.country"); const wchar_t *address_toCity = jResp.stringOf(L"address_to.city"); const wchar_t *address_toState = jResp.stringOf(L"address_to.state"); const wchar_t *address_toZip = jResp.stringOf(L"address_to.zip"); const wchar_t *address_toCountry = jResp.stringOf(L"address_to.country"); const wchar_t *eta = jResp.stringOf(L"eta"); const wchar_t *original_eta = jResp.stringOf(L"original_eta"); const wchar_t *servicelevelToken = jResp.stringOf(L"servicelevel.token"); const wchar_t *servicelevelName = jResp.stringOf(L"servicelevel.name"); const wchar_t *metadata = jResp.stringOf(L"metadata"); const wchar_t *tracking_statusObject_created = jResp.stringOf(L"tracking_status.object_created"); const wchar_t *tracking_statusObject_updated = jResp.stringOf(L"tracking_status.object_updated"); const wchar_t *tracking_statusObject_id = jResp.stringOf(L"tracking_status.object_id"); const wchar_t *tracking_statusStatus = jResp.stringOf(L"tracking_status.status"); const wchar_t *tracking_statusStatus_details = jResp.stringOf(L"tracking_status.status_details"); const wchar_t *tracking_statusStatus_date = jResp.stringOf(L"tracking_status.status_date"); const wchar_t *tracking_statusSubstatus = jResp.stringOf(L"tracking_status.substatus"); const wchar_t *tracking_statusLocationCity = jResp.stringOf(L"tracking_status.location.city"); const wchar_t *tracking_statusLocationState = jResp.stringOf(L"tracking_status.location.state"); const wchar_t *tracking_statusLocationZip = jResp.stringOf(L"tracking_status.location.zip"); const wchar_t *tracking_statusLocationCountry = jResp.stringOf(L"tracking_status.location.country"); const wchar_t *transaction = jResp.stringOf(L"transaction"); bool test = jResp.BoolOf(L"test"); int i = 0; int count_i = jResp.SizeOfArray(L"messages"); while (i < count_i) { jResp.put_I(i); i = i + 1; } i = 0; count_i = jResp.SizeOfArray(L"tracking_history"); while (i < count_i) { jResp.put_I(i); object_created = jResp.stringOf(L"tracking_history[i].object_created"); object_updated = jResp.stringOf(L"tracking_history[i].object_updated"); object_id = jResp.stringOf(L"tracking_history[i].object_id"); status = jResp.stringOf(L"tracking_history[i].status"); status_details = jResp.stringOf(L"tracking_history[i].status_details"); status_date = jResp.stringOf(L"tracking_history[i].status_date"); substatus = jResp.stringOf(L"tracking_history[i].substatus"); locationCity = jResp.stringOf(L"tracking_history[i].location.city"); locationState = jResp.stringOf(L"tracking_history[i].location.state"); locationZip = jResp.stringOf(L"tracking_history[i].location.zip"); locationCountry = jResp.stringOf(L"tracking_history[i].location.country"); i = i + 1; } } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.