Unicode C++
Unicode 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 Unicode C++ Downloads
#include <CkHttpW.h>
#include <CkJsonObjectW.h>
#include <CkHttpResponseW.h>
#include <CkStringBuilderW.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.
CkHttpW 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"
// }
// ]
// }
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;
success = http.HttpJson(L"POST",L"https://api.goshippo.com/customs/declarations/",json,L"application/json",resp);
if (success == 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");
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 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;
}
}