Sample code for 30+ languages & platforms
Rust

Shippo Create a Refund

See more Shippo Examples

Demonstrates how to refund a shipping label.

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/refunds/ \
//     -H "Authorization: ShippoToken <API_Token>" \
//     -d transaction="4503427478ea45a899e9b54abc4c5803"

let req = chilkat::HttpRequest::new();
req.set_http_verb("POST");
req.set_path("/refunds/");
req.set_content_type("application/x-www-form-urlencoded");
req.add_param("transaction", "4503427478ea45a899e9b54abc4c5803");

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

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

// {
//   "object_created": "2014-04-21T07:12:41.044Z",
//   "object_id": "bd7b8379a2e847bcb0818125943dde5d",
//   "object_owner": "shippotle@goshippo.com",
//   "object_updated": "2014-04-21T07:12:41.045Z",
//   "status": "QUEUED",
//   "transaction": "35ed59f23a514ecfa2faeaed93a00086"
// }

// 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_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 status = j_resp.string_of("status").unwrap_or_default();
let transaction = j_resp.string_of("transaction").unwrap_or_default();