Sample code for 30+ languages & platforms
Rust

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 Rust Downloads

Rust

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

let http = chilkat::Http::new();

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

let json = chilkat::JsonObject::new();
let _ = json.update_string("contents_type", "MERCHANDISE");
let _ = json.update_string("non_delivery_option", "RETURN");
let _ = json.update_bool("certify", true);
let _ = json.update_string("certify_signer", "Simon Kreuz");
let _ = json.update_string("incoterm", "DDU");
let _ = json.update_string("items[0].description", "T-shirt");
let _ = json.update_int("items[0].quantity", 20);
let _ = json.update_string("items[0].net_weight", "5");
let _ = json.update_string("items[0].mass_unit", "lb");
let _ = json.update_string("items[0].value_amount", "200");
let _ = json.update_string("items[0].value_currency", "USD");
let _ = json.update_string("items[0].tariff_number", "");
let _ = json.update_string("items[0].origin_country", "US");

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

let resp = chilkat::HttpResponse::new();
if http.http_json("POST", "https://api.goshippo.com/customs/declarations/", &json, "application/json", &resp).is_err() {
    println!("{}", http.last_error_text());
    return;
}

let sb_response_body = chilkat::StringBuilder::new();
let _ = resp.get_body_sb(&sb_response_body);
let j_resp = chilkat::JsonObject::new();
let _ = j_resp.load_sb(&sb_response_body);
j_resp.set_emit_compact(false);

println!("Response Body:");
println!("{}", j_resp.emit().unwrap_or_default());

let resp_status_code = resp.status_code();
println!("Response Status Code = {}", resp_status_code);
if resp_status_code >= 400 {
    println!("Response Header:");
    println!("{}", resp.header());
    println!("Failed.");
    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

let object_created = j_resp.string_of("object_created").unwrap_or_default();
let object_updated = j_resp.string_of("object_updated").unwrap_or_default();
let object_id = j_resp.string_of("object_id").unwrap_or_default();
let object_owner = j_resp.string_of("object_owner").unwrap_or_default();
let object_state = j_resp.string_of("object_state").unwrap_or_default();
let address_importer = j_resp.string_of("address_importer").unwrap_or_default();
let certify_signer = j_resp.string_of("certify_signer").unwrap_or_default();
let certify = j_resp.bool_of("certify");
let non_delivery_option = j_resp.string_of("non_delivery_option").unwrap_or_default();
let contents_type = j_resp.string_of("contents_type").unwrap_or_default();
let contents_explanation = j_resp.string_of("contents_explanation").unwrap_or_default();
let exporter_reference = j_resp.string_of("exporter_reference").unwrap_or_default();
let importer_reference = j_resp.string_of("importer_reference").unwrap_or_default();
let invoice = j_resp.string_of("invoice").unwrap_or_default();
let commercial_invoice = j_resp.bool_of("commercial_invoice");
let license = j_resp.string_of("license").unwrap_or_default();
let certificate = j_resp.string_of("certificate").unwrap_or_default();
let notes = j_resp.string_of("notes").unwrap_or_default();
let eel_pfc = j_resp.string_of("eel_pfc").unwrap_or_default();
let aes_itn = j_resp.string_of("aes_itn").unwrap_or_default();
let disclaimer = j_resp.string_of("disclaimer").unwrap_or_default();
let incoterm = j_resp.string_of("incoterm").unwrap_or_default();
let metadata = j_resp.string_of("metadata").unwrap_or_default();
let test = j_resp.bool_of("test");
let duties_payor = j_resp.string_of("duties_payor").unwrap_or_default();
let mut i = 0;
let count_i = j_resp.size_of_array("items");
while i < count_i {
    j_resp.set_i(i);
    let _ = j_resp.string_of("items[i]").unwrap_or_default();
    i = i + 1;
}