Sample code for 30+ languages & platforms
Rust

Update an Inventory Listing using OAuth1 Authentication

See more Etsy Examples

Updates an inventory listing. This example uses OAuth1 authentication instead of providing an api_key=MY_ETSY_KEYSTRING query parameter.

Chilkat Rust Downloads

Rust

// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

let rest = chilkat::Rest::new();

// See this example for getting an OAuth1 token for Etsy

let json = chilkat::JsonObject::new();
if json.load_file("qa_data/tokens/etsy.json").is_err() {
    println!("Failed to load previously fetched Etsy OAuth1 access token.");
    return;
}

let oauth1 = chilkat::OAuth1::new();

oauth1.set_consumer_key("app_keystring");
oauth1.set_consumer_secret("app_shared_secret");
oauth1.set_token(&json.string_of("oauth_token").unwrap_or_default());
oauth1.set_token_secret(&json.string_of("oauth_token_secret").unwrap_or_default());
oauth1.set_signature_method("HMAC-SHA1");
let _ = oauth1.gen_nonce(16);

let auto_reconnect = true;
let tls = true;
if rest.connect("openapi.etsy.com", 443, tls, auto_reconnect).is_err() {
    println!("{}", rest.last_error_text());
    return;
}

// Tell the REST object to use the OAuth1 object.
let _ = rest.set_auth_o_auth1(&oauth1, true).is_ok();

let json_text = "[{\"product_id\":1999949999,\"property_values\":[],\"offerings\":[{\"offering_id\":9999905883,\"price\":\"36.23\",\"quantity\":1}]}]".to_string();

let _ = rest.add_query_param("products", &json_text);
let _ = rest.add_header("Content-Type", "application/x-www-form-urlencoded");

let Ok(json_response_text) = rest.full_request_form_url_encoded("PUT", "/v2/listings/228827035/inventory") else {
    println!("{}", rest.last_error_text());
    return;
};

let json_response = chilkat::JsonObject::new();
let _ = json_response.load(&json_response_text);
json_response.set_emit_compact(false);

println!("{}", json_response.emit().unwrap_or_default());

println!("Response status code: {}", rest.response_status_code());