Sample code for 30+ languages & platforms
Rust

Shippo Adding Metadata

See more Shippo Examples

Demonstrates how to add metadata to the tracking request through a POST request.

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/tracks/ \
//     -H "Authorization: ShippoToken <API_TOKEN>" \
//     -d carrier="shippo" \
//     -d tracking_number="SHIPPO_TRANSIT" \
//     -d metadata="Order 000123"

let req = chilkat::HttpRequest::new();
req.set_http_verb("POST");
req.set_path("/tracks/");
req.set_content_type("application/x-www-form-urlencoded");
req.add_param("carrier", "shippo");
req.add_param("tracking_number", "SHIPPO_TRANSIT");
req.add_param("metadata", "Order 000123");

req.add_header("Authorization", "ShippoToken <API_TOKEN>");

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

// {
//   "messages": [
//   ],
//   "carrier": "shippo",
//   "tracking_number": "SHIPPO_TRANSIT",
//   "address_from": {
//     "city": "San Francisco",
//     "state": "CA",
//     "zip": "94103",
//     "country": "US"
//   },
//   "address_to": {
//     "city": "Chicago",
//     "state": "IL",
//     "zip": "60611",
//     "country": "US"
//   },
//   "eta": "2019-07-07T17:07:44.989Z",
//   "original_eta": "2019-07-07T17:07:44.989Z",
//   "servicelevel": {
//     "token": "shippo_priority",
//     "name": "Priority Mail"
//   },
//   "metadata": "Shippo test tracking",
//   "tracking_status": {
//     "object_created": "2019-07-04T17:07:45.003Z",
//     "object_updated": null,
//     "object_id": "ee35fb56f5d04021b36168abedc04573",
//     "status": "TRANSIT",
//     "status_details": "Your shipment has departed from the origin.",
//     "status_date": "2019-07-03T15:02:45.003Z",
//     "substatus": null,
//     "location": {
//       "city": "San Francisco",
//       "state": "CA",
//       "zip": "94103",
//       "country": "US"
//     }
//   },
//   "tracking_history": [
//     {
//       "object_created": "2019-07-04T17:07:45.005Z",
//       "object_updated": null,
//       "object_id": "2121a59f53ed42e0ae0436f636179156",
//       "status": "UNKNOWN",
//       "status_details": "The carrier has received the electronic shipment information.",
//       "status_date": "2019-07-02T12:57:45.005Z",
//       "substatus": null,
//       "location": {
//         "city": "San Francisco",
//         "state": "CA",
//         "zip": "94103",
//         "country": "US"
//       }
//     },
//     {
//       "object_created": "2019-07-04T17:07:45.005Z",
//       "object_updated": null,
//       "object_id": "06f949db1a8245beaa28df264b368a76",
//       "status": "TRANSIT",
//       "status_details": "Your shipment has departed from the origin.",
//       "status_date": "2019-07-03T15:02:45.005Z",
//       "substatus": null,
//       "location": {
//         "city": "San Francisco",
//         "state": "CA",
//         "zip": "94103",
//         "country": "US"
//       }
//     }
//   ],
//   "transaction": null,
//   "test": true
// }

// 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 carrier = j_resp.string_of("carrier").unwrap_or_default();
let tracking_number = j_resp.string_of("tracking_number").unwrap_or_default();
let address_from_city = j_resp.string_of("address_from.city").unwrap_or_default();
let address_from_state = j_resp.string_of("address_from.state").unwrap_or_default();
let address_from_zip = j_resp.string_of("address_from.zip").unwrap_or_default();
let address_from_country = j_resp.string_of("address_from.country").unwrap_or_default();
let address_to_city = j_resp.string_of("address_to.city").unwrap_or_default();
let address_to_state = j_resp.string_of("address_to.state").unwrap_or_default();
let address_to_zip = j_resp.string_of("address_to.zip").unwrap_or_default();
let address_to_country = j_resp.string_of("address_to.country").unwrap_or_default();
let eta = j_resp.string_of("eta").unwrap_or_default();
let original_eta = j_resp.string_of("original_eta").unwrap_or_default();
let servicelevel_token = j_resp.string_of("servicelevel.token").unwrap_or_default();
let servicelevel_name = j_resp.string_of("servicelevel.name").unwrap_or_default();
let metadata = j_resp.string_of("metadata").unwrap_or_default();
let tracking_status_object_created = j_resp.string_of("tracking_status.object_created").unwrap_or_default();
let tracking_status_object_updated = j_resp.string_of("tracking_status.object_updated").unwrap_or_default();
let tracking_status_object_id = j_resp.string_of("tracking_status.object_id").unwrap_or_default();
let tracking_status_status = j_resp.string_of("tracking_status.status").unwrap_or_default();
let tracking_status_status_details = j_resp.string_of("tracking_status.status_details").unwrap_or_default();
let tracking_status_status_date = j_resp.string_of("tracking_status.status_date").unwrap_or_default();
let tracking_status_substatus = j_resp.string_of("tracking_status.substatus").unwrap_or_default();
let tracking_status_location_city = j_resp.string_of("tracking_status.location.city").unwrap_or_default();
let tracking_status_location_state = j_resp.string_of("tracking_status.location.state").unwrap_or_default();
let tracking_status_location_zip = j_resp.string_of("tracking_status.location.zip").unwrap_or_default();
let tracking_status_location_country = j_resp.string_of("tracking_status.location.country").unwrap_or_default();
let transaction = j_resp.string_of("transaction").unwrap_or_default();
let test = j_resp.bool_of("test");
let mut i = 0;
let mut count_i = j_resp.size_of_array("messages");
while i < count_i {
    j_resp.set_i(i);
    i = i + 1;
}

i = 0;
count_i = j_resp.size_of_array("tracking_history");
while i < count_i {
    j_resp.set_i(i);
    let _ = j_resp.string_of("tracking_history[i].object_created").unwrap_or_default();
    let _ = j_resp.string_of("tracking_history[i].object_updated").unwrap_or_default();
    let _ = j_resp.string_of("tracking_history[i].object_id").unwrap_or_default();
    let _ = j_resp.string_of("tracking_history[i].status").unwrap_or_default();
    let _ = j_resp.string_of("tracking_history[i].status_details").unwrap_or_default();
    let _ = j_resp.string_of("tracking_history[i].status_date").unwrap_or_default();
    let _ = j_resp.string_of("tracking_history[i].substatus").unwrap_or_default();
    let _ = j_resp.string_of("tracking_history[i].location.city").unwrap_or_default();
    let _ = j_resp.string_of("tracking_history[i].location.state").unwrap_or_default();
    let _ = j_resp.string_of("tracking_history[i].location.zip").unwrap_or_default();
    let _ = j_resp.string_of("tracking_history[i].location.country").unwrap_or_default();
    i = i + 1;
}