Rust
Rust
Etsy: Get the Inventory for a Listing
See more Etsy Examples
Gets the inventory for a listing.Chilkat Rust Downloads
// 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 -X GET \
// https://openapi.etsy.com/v2/listings/listing_id/inventory?api_key=MY_ETSY_KEYSTRING
let sb_response_body = chilkat::StringBuilder::new();
if http.quick_get_sb("https://openapi.etsy.com/v2/listings/listing_id/inventory?api_key=MY_ETSY_KEYSTRING", &sb_response_body).is_err() {
println!("{}", http.last_error_text());
return;
}
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 = http.last_status();
println!("Response Status Code = {}", resp_status_code);
if resp_status_code >= 400 {
println!("Response Header:");
println!("{}", http.last_header());
println!("Failed.");
return;
}
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "count": 1,
// "results": {
// "products": [
// {
// "product_id": 3361120103,
// "property_values": [
// ],
// "offerings": [
// {
// "offering_id": 3579642570,
// "price": {
// "amount": 16000,
// "divisor": 100,
// "currency_code": "USD",
// "currency_formatted_short": "$160.00",
// "currency_formatted_long": "$160.00 USD",
// "currency_formatted_raw": "160.00"
// },
// "quantity": 1
// }
// ]
// }
// ]
// },
// "params": {
// "listing_id": "720138253",
// "write_missing_inventory": false
// },
// "type": "ListingInventory",
// "pagination": {}
// }
// 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 mut j: i32 = 0;
let mut count_j: i32 = 0;
let count = j_resp.int_of("count");
let params_listing_id = j_resp.string_of("params.listing_id").unwrap_or_default();
let params_write_missing_inventory = j_resp.bool_of("params.write_missing_inventory");
let v_type = j_resp.string_of("type").unwrap_or_default();
let mut i = 0;
let count_i = j_resp.size_of_array("results.products");
while i < count_i {
j_resp.set_i(i);
let _ = j_resp.int_of("results.products[i].product_id");
j = 0;
count_j = j_resp.size_of_array("results.products[i].property_values");
while j < count_j {
j_resp.set_j(j);
j = j + 1;
}
j = 0;
count_j = j_resp.size_of_array("results.products[i].offerings");
while j < count_j {
j_resp.set_j(j);
let _ = j_resp.int_of("results.products[i].offerings[j].offering_id");
let _ = j_resp.int_of("results.products[i].offerings[j].price.amount");
let _ = j_resp.int_of("results.products[i].offerings[j].price.divisor");
let _ = j_resp.string_of("results.products[i].offerings[j].price.currency_code").unwrap_or_default();
let _ = j_resp.string_of("results.products[i].offerings[j].price.currency_formatted_short").unwrap_or_default();
let _ = j_resp.string_of("results.products[i].offerings[j].price.currency_formatted_long").unwrap_or_default();
let _ = j_resp.string_of("results.products[i].offerings[j].price.currency_formatted_raw").unwrap_or_default();
let _ = j_resp.int_of("results.products[i].offerings[j].quantity");
j = j + 1;
}
i = i + 1;
}