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 Create Customs DeclarationDemonstrates how to create a customs declaration and send a POST request with the necessary information to the Customs Declarations endpoint. For more information, see https://goshippo.com/docs/international/
#include <CkHttpW.h> #include <CkJsonObjectW.h> #include <CkHttpResponseW.h> #include <CkStringBuilderW.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/customs/declarations/ \ // -H "Authorization: ShippoToken <API_TOKEN>" \ // -H "Content-Type: application/json" \ // -d '{ // "contents_type": "MERCHANDISE", // "non_delivery_option": "RETURN", // "certify": true, // "certify_signer": "Simon Kreuz", // "incoterm": "DDU", // "items": [{ // "description": "T-shirt", // "quantity": 20, // "net_weight": "5", // "mass_unit": "lb", // "value_amount": "200", // "value_currency": "USD", // "tariff_number": "", // "origin_country": "US" // }] // }' // Use this online tool to generate code from sample JSON: // Generate Code to Create JSON // The following JSON is sent in the request body. // { // "contents_type": "MERCHANDISE", // "non_delivery_option": "RETURN", // "certify": true, // "certify_signer": "Simon Kreuz", // "incoterm": "DDU", // "items": [ // { // "description": "T-shirt", // "quantity": 20, // "net_weight": "5", // "mass_unit": "lb", // "value_amount": "200", // "value_currency": "USD", // "tariff_number": "", // "origin_country": "US" // } // ] // } CkJsonObjectW json; json.UpdateString(L"contents_type",L"MERCHANDISE"); json.UpdateString(L"non_delivery_option",L"RETURN"); json.UpdateBool(L"certify",true); json.UpdateString(L"certify_signer",L"Simon Kreuz"); json.UpdateString(L"incoterm",L"DDU"); json.UpdateString(L"items[0].description",L"T-shirt"); json.UpdateInt(L"items[0].quantity",20); json.UpdateString(L"items[0].net_weight",L"5"); json.UpdateString(L"items[0].mass_unit",L"lb"); json.UpdateString(L"items[0].value_amount",L"200"); json.UpdateString(L"items[0].value_currency",L"USD"); json.UpdateString(L"items[0].tariff_number",L""); json.UpdateString(L"items[0].origin_country",L"US"); http.SetRequestHeader(L"Authorization",L"ShippoToken <API_TOKEN>"); http.SetRequestHeader(L"Content-Type",L"application/json"); CkHttpResponseW *resp = http.PostJson3(L"https://api.goshippo.com/customs/declarations/",L"application/json",json); 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) // { // "object_created": "2019-07-04T16:00:29.043Z", // "object_updated": "2019-07-04T16:00:29.043Z", // "object_id": "4a1e6ab7b1ba49ed9bc6cb1a8798e0fd", // "object_owner": "admin@chilkatsoft.com", // "object_state": "VALID", // "address_importer": null, // "certify_signer": "Simon Kreuz", // "certify": true, // "items": [ // "4096c68693364b7ea0af72fb869ee861" // ], // "non_delivery_option": "RETURN", // "contents_type": "MERCHANDISE", // "contents_explanation": "", // "exporter_reference": "", // "importer_reference": "", // "invoice": "", // "commercial_invoice": false, // "license": "", // "certificate": "", // "notes": "", // "eel_pfc": "", // "aes_itn": "", // "disclaimer": "", // "incoterm": "DDU", // "metadata": "", // "test": true, // "duties_payor": null // } // 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 *strVal = 0; const wchar_t *object_created = jResp.stringOf(L"object_created"); const wchar_t *object_updated = jResp.stringOf(L"object_updated"); const wchar_t *object_id = jResp.stringOf(L"object_id"); const wchar_t *object_owner = jResp.stringOf(L"object_owner"); const wchar_t *object_state = jResp.stringOf(L"object_state"); const wchar_t *address_importer = jResp.stringOf(L"address_importer"); const wchar_t *certify_signer = jResp.stringOf(L"certify_signer"); bool certify = jResp.BoolOf(L"certify"); const wchar_t *non_delivery_option = jResp.stringOf(L"non_delivery_option"); const wchar_t *contents_type = jResp.stringOf(L"contents_type"); const wchar_t *contents_explanation = jResp.stringOf(L"contents_explanation"); const wchar_t *exporter_reference = jResp.stringOf(L"exporter_reference"); const wchar_t *importer_reference = jResp.stringOf(L"importer_reference"); const wchar_t *invoice = jResp.stringOf(L"invoice"); bool commercial_invoice = jResp.BoolOf(L"commercial_invoice"); const wchar_t *license = jResp.stringOf(L"license"); const wchar_t *certificate = jResp.stringOf(L"certificate"); const wchar_t *notes = jResp.stringOf(L"notes"); const wchar_t *eel_pfc = jResp.stringOf(L"eel_pfc"); const wchar_t *aes_itn = jResp.stringOf(L"aes_itn"); const wchar_t *disclaimer = jResp.stringOf(L"disclaimer"); const wchar_t *incoterm = jResp.stringOf(L"incoterm"); const wchar_t *metadata = jResp.stringOf(L"metadata"); bool test = jResp.BoolOf(L"test"); const wchar_t *duties_payor = jResp.stringOf(L"duties_payor"); int i = 0; int count_i = jResp.SizeOfArray(L"items"); while (i < count_i) { jResp.put_I(i); strVal = jResp.stringOf(L"items[i]"); i = i + 1; } } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.