Sample code for 30+ languages & platforms
Rust

Shippo Create an Order

See more Shippo Examples

Demonstrates how to create an order with all the information about your order by sending a POST request to the orders 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/orders/ \
//     -H "Authorization: ShippoToken <API_Token>" \
//     -H "Content-Type: application/json"  \
//     -d '{
//             "to_address": {
//                 "city": "San Francisco",
//                 "company": "Shippo",
//                 "country": "US",
//                 "email": "shippotle@goshippo.com",
//                 "name": "Mr Hippo",
//                 "phone": "15553419393",
//                 "state": "CA",
//                 "street1": "215 Clayton St.",
//                 "zip": "94117"
//             },
//             "line_items": [
//                 {
//                     "quantity": 1,
//                     "sku": "HM-123",
//                     "title": "Hippo Magazines",
//                     "total_price": "12.10",
//                     "currency": "USD",
//                     "weight": "0.40",
//                     "weight_unit": "lb"
//                 }
//             ],
//             "placed_at": "2016-09-23T01:28:12Z",
//             "order_number": "#1068",
//             "order_status": "PAID",
//             "shipping_cost": "12.83",
//             "shipping_cost_currency": "USD",
//             "shipping_method": "USPS First Class Package",
//             "subtotal_price": "12.10",
//             "total_price": "24.93",
//             "total_tax": "0.00",
//             "currency": "USD",
//             "weight": "0.40",
//             "weight_unit": "lb"
//         }'

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

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

// {
//   "to_address": {
//     "city": "San Francisco",
//     "company": "Shippo",
//     "country": "US",
//     "email": "shippotle@goshippo.com",
//     "name": "Mr Hippo",
//     "phone": "15553419393",
//     "state": "CA",
//     "street1": "215 Clayton St.",
//     "zip": "94117"
//   },
//   "line_items": [
//     {
//       "quantity": 1,
//       "sku": "HM-123",
//       "title": "Hippo Magazines",
//       "total_price": "12.10",
//       "currency": "USD",
//       "weight": "0.40",
//       "weight_unit": "lb"
//     }
//   ],
//   "placed_at": "2016-09-23T01:28:12Z",
//   "order_number": "#1068",
//   "order_status": "PAID",
//   "shipping_cost": "12.83",
//   "shipping_cost_currency": "USD",
//   "shipping_method": "USPS First Class Package",
//   "subtotal_price": "12.10",
//   "total_price": "24.93",
//   "total_tax": "0.00",
//   "currency": "USD",
//   "weight": "0.40",
//   "weight_unit": "lb"
// }

let json = chilkat::JsonObject::new();
let _ = json.update_string("to_address.city", "San Francisco");
let _ = json.update_string("to_address.company", "Shippo");
let _ = json.update_string("to_address.country", "US");
let _ = json.update_string("to_address.email", "shippotle@goshippo.com");
let _ = json.update_string("to_address.name", "Mr Hippo");
let _ = json.update_string("to_address.phone", "15553419393");
let _ = json.update_string("to_address.state", "CA");
let _ = json.update_string("to_address.street1", "215 Clayton St.");
let _ = json.update_string("to_address.zip", "94117");
let _ = json.update_int("line_items[0].quantity", 1);
let _ = json.update_string("line_items[0].sku", "HM-123");
let _ = json.update_string("line_items[0].title", "Hippo Magazines");
let _ = json.update_string("line_items[0].total_price", "12.10");
let _ = json.update_string("line_items[0].currency", "USD");
let _ = json.update_string("line_items[0].weight", "0.40");
let _ = json.update_string("line_items[0].weight_unit", "lb");
let _ = json.update_string("placed_at", "2016-09-23T01:28:12Z");
let _ = json.update_string("order_number", "#1068");
let _ = json.update_string("order_status", "PAID");
let _ = json.update_string("shipping_cost", "12.83");
let _ = json.update_string("shipping_cost_currency", "USD");
let _ = json.update_string("shipping_method", "USPS First Class Package");
let _ = json.update_string("subtotal_price", "12.10");
let _ = json.update_string("total_price", "24.93");
let _ = json.update_string("total_tax", "0.00");
let _ = json.update_string("currency", "USD");
let _ = json.update_string("weight", "0.40");
let _ = json.update_string("weight_unit", "lb");

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/orders/", &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)

// {}

// Sample code for parsing the JSON response...
// Use the following online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON