Rust
Rust
Shopware 6 - Rename Category
See more Shopware 6 Examples
Changes the name of an existing category.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();
// You'll need to know the category's id to update the name.
// See Find Shopware Category by Name for example code.
// Load the access token previously obtained in Shopware 6 OAuth2 Client Credentials
let json_token = chilkat::JsonObject::new();
let _ = json_token.load_file("qa_data/tokens/shopware6.json");
// This causes the "Authorization: Bearer <access_token>" header to be added.
http.set_auth_token(&json_token.string_of("access_token").unwrap_or_default());
// Send a PATCH request where the category id is in the path and the new name is in the JSON body, like this:
// PATCH /api/v3/category/ab6e524bf224404cb4b675a76550b8cd
// {
// "name": "new_category_name"
// }
let category_id = "ab6e524bf224404cb4b675a76550b8cd".to_string();
let sb_url = chilkat::StringBuilder::new();
let _ = sb_url.append("https://my-shopware-6-shop.de/api/v3/category/");
let _ = sb_url.append(&category_id);
// Rename the category to "TestABC"
let json = chilkat::JsonObject::new();
let _ = json.update_string("name", "TestABC");
let url = sb_url.get_as_string().unwrap_or_default();
let resp = chilkat::HttpResponse::new();
if http.http_json("PATCH", &url, &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);
// A 204 response status code indicates success.
// The response body will be empty when successful.
println!("Response Body:");
println!("{}", j_resp.emit().unwrap_or_default());
// If we get a 401 response, it may be that our access token expired and we need to fetch a new one.
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;
}