Sample code for 30+ languages & platforms
Rust

Shippo Create a New Manifest

See more Shippo Examples

Demonstrates how to create a manifest for your shipments.

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/manifests/
//     -H "Authorization: ShippoToken shippo_test_831a7a042784f523b95db65444e6e084b636764b" \
//     -H "Content-Type: application/json"  \
//     -d '{
//           "carrier_account": "b741b99f95e841639b54272834bc478c",
//           "shipment_date": "2014-05-16T23:59:59Z",
//           "address_from": "28828839a2b04e208ac2aa4945fbca9a",
//           "transactions": [
//             "64bba01845ef40d29374032599f22588", 
//             "c169aa586a844cc49da00d0272b590e1"
//             ],
//           "async": false
//         }'

// Use this online tool to generate code from sample JSON:
// Generate Code to Create JSON

// The following JSON is sent in the request body.

// {
//   "carrier_account": "b741b99f95e841639b54272834bc478c",
//   "shipment_date": "2014-05-16T23:59:59Z",
//   "address_from": "28828839a2b04e208ac2aa4945fbca9a",
//   "transactions": [
//     "64bba01845ef40d29374032599f22588",
//     "c169aa586a844cc49da00d0272b590e1"
//   ],
//   "async": false
// }

let json = chilkat::JsonObject::new();
let _ = json.update_string("carrier_account", "b741b99f95e841639b54272834bc478c");
let _ = json.update_string("shipment_date", "2014-05-16T23:59:59Z");
let _ = json.update_string("address_from", "28828839a2b04e208ac2aa4945fbca9a");
let _ = json.update_string("transactions[0]", "64bba01845ef40d29374032599f22588");
let _ = json.update_string("transactions[1]", "c169aa586a844cc49da00d0272b590e1");
let _ = json.update_bool("async", false);

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

let resp = chilkat::HttpResponse::new();
if http.http_json("POST", "https://api.goshippo.com/manifests/", &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)

// {
//   "address_from": "28828839a2b04e208ac2aa4945fbca9a",
//   "carrier_account": "b741b99f95e841639b54272834bc478c",
//   "documents": [
//     "https://shippo-delivery.s3.amazonaws.com/0fadebf6f60c4aca95fa01bcc59c79ae.pdf?Signature=tlQU3RECwdHUQJQadwqg5bAzGFQ%3D&Expires=1402803835&AWSAccessKeyId=AKIAJTHP3LLFMYAWALIA"
//   ],
//   "object_created": "2014-05-16T03:43:52.765Z",
//   "object_id": "0fadebf6f60c4aca95fa01bcc59c79ae",
//   "object_owner": "mrhippo@goshippo.com",
//   "object_updated": "2014-05-16T03:43:55.445Z",
//   "shipment_date": "2014-05-16T23:59:59Z",
//   "status": "SUCCESS",
//   "transactions": [
//     "64bba01845ef40d29374032599f22588",
//     "c169aa586a844cc49da00d0272b590e1"
//   ]
// }

// 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 address_from = j_resp.string_of("address_from").unwrap_or_default();
let carrier_account = j_resp.string_of("carrier_account").unwrap_or_default();
let object_created = j_resp.string_of("object_created").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_updated = j_resp.string_of("object_updated").unwrap_or_default();
let shipment_date = j_resp.string_of("shipment_date").unwrap_or_default();
let status = j_resp.string_of("status").unwrap_or_default();
let mut i = 0;
let mut count_i = j_resp.size_of_array("documents");
while i < count_i {
    j_resp.set_i(i);
    let _ = j_resp.string_of("documents[i]").unwrap_or_default();
    i = i + 1;
}

i = 0;
count_i = j_resp.size_of_array("transactions");
while i < count_i {
    j_resp.set_i(i);
    let _ = j_resp.string_of("transactions[i]").unwrap_or_default();
    i = i + 1;
}