Sample code for 30+ languages & platforms
C++

Shippo Create Customs Declaration

See more Shippo Examples

Demonstrates how to create a customs declaration and send a POST request with the necessary information to the Customs Declarations endpoint.

Chilkat C++ Downloads

C++
#include <CkHttp.h>
#include <CkJsonObject.h>
#include <CkHttpResponse.h>
#include <CkStringBuilder.h>

void ChilkatSample(void)
    {
    bool success = false;

    //  This example assumes the Chilkat API to have been previously unlocked.
    //  See Global Unlock Sample for sample code.

    CkHttp http;

    //  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"
    //      }
    //    ]
    //  }

    CkJsonObject json;
    json.UpdateString("contents_type","MERCHANDISE");
    json.UpdateString("non_delivery_option","RETURN");
    json.UpdateBool("certify",true);
    json.UpdateString("certify_signer","Simon Kreuz");
    json.UpdateString("incoterm","DDU");
    json.UpdateString("items[0].description","T-shirt");
    json.UpdateInt("items[0].quantity",20);
    json.UpdateString("items[0].net_weight","5");
    json.UpdateString("items[0].mass_unit","lb");
    json.UpdateString("items[0].value_amount","200");
    json.UpdateString("items[0].value_currency","USD");
    json.UpdateString("items[0].tariff_number","");
    json.UpdateString("items[0].origin_country","US");

    http.SetRequestHeader("Authorization","ShippoToken <API_TOKEN>");
    http.SetRequestHeader("Content-Type","application/json");

    CkHttpResponse resp;
    success = http.HttpJson("POST","https://api.goshippo.com/customs/declarations/",json,"application/json",resp);
    if (success == false) {
        std::cout << http.lastErrorText() << "\r\n";
        return;
    }

    CkStringBuilder sbResponseBody;
    resp.GetBodySb(sbResponseBody);
    CkJsonObject jResp;
    jResp.LoadSb(sbResponseBody);
    jResp.put_EmitCompact(false);

    std::cout << "Response Body:" << "\r\n";
    std::cout << jResp.emit() << "\r\n";

    int respStatusCode = resp.get_StatusCode();
    std::cout << "Response Status Code = " << respStatusCode << "\r\n";
    if (respStatusCode >= 400) {
        std::cout << "Response Header:" << "\r\n";
        std::cout << resp.header() << "\r\n";
        std::cout << "Failed." << "\r\n";
        return;
    }

    //  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 char *strVal = 0;

    const char *object_created = jResp.stringOf("object_created");
    const char *object_updated = jResp.stringOf("object_updated");
    const char *object_id = jResp.stringOf("object_id");
    const char *object_owner = jResp.stringOf("object_owner");
    const char *object_state = jResp.stringOf("object_state");
    const char *address_importer = jResp.stringOf("address_importer");
    const char *certify_signer = jResp.stringOf("certify_signer");
    bool certify = jResp.BoolOf("certify");
    const char *non_delivery_option = jResp.stringOf("non_delivery_option");
    const char *contents_type = jResp.stringOf("contents_type");
    const char *contents_explanation = jResp.stringOf("contents_explanation");
    const char *exporter_reference = jResp.stringOf("exporter_reference");
    const char *importer_reference = jResp.stringOf("importer_reference");
    const char *invoice = jResp.stringOf("invoice");
    bool commercial_invoice = jResp.BoolOf("commercial_invoice");
    const char *license = jResp.stringOf("license");
    const char *certificate = jResp.stringOf("certificate");
    const char *notes = jResp.stringOf("notes");
    const char *eel_pfc = jResp.stringOf("eel_pfc");
    const char *aes_itn = jResp.stringOf("aes_itn");
    const char *disclaimer = jResp.stringOf("disclaimer");
    const char *incoterm = jResp.stringOf("incoterm");
    const char *metadata = jResp.stringOf("metadata");
    bool test = jResp.BoolOf("test");
    const char *duties_payor = jResp.stringOf("duties_payor");
    int i = 0;
    int count_i = jResp.SizeOfArray("items");
    while (i < count_i) {
        jResp.put_I(i);
        strVal = jResp.stringOf("items[i]");
        i = i + 1;
    }
    }