Sample code for 30+ languages & platforms
Rust

Shopware List Categories

See more Shopware Examples

List categories in your Shopware database.

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();

http.set_login("api_username");
http.set_password("api_key");
http.set_basic_auth(true);

let sb_response_body = chilkat::StringBuilder::new();
if http.quick_get_sb("https://my-shopware-shop.com/api/categories?limit=2", &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());

// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)

// {
//   "data": [
//     {
//       "id": 1,
//       "active": true,
//       "name": "Root",
//       "position": 0,
//       "parentId": null,
//       "mediaId": null,
//       "childrenCount": "3",
//       "articleCount": "0"
//     },
//     {
//       "id": 384,
//       "active": true,
//       "name": "Deutsch",
//       "position": 0,
//       "parentId": 1,
//       "mediaId": null,
//       "childrenCount": "9",
//       "articleCount": "32"
//     }
//   ],
//   "total": 118,
//   "success": true
// }

// 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 total = j_resp.int_of("total");
let _ = j_resp.bool_of("success");
let mut i = 0;
let count_i = j_resp.size_of_array("data");
while i < count_i {
    j_resp.set_i(i);
    let _ = j_resp.int_of("data[i].id");
    let _ = j_resp.bool_of("data[i].active");
    let _ = j_resp.string_of("data[i].name").unwrap_or_default();
    let _ = j_resp.int_of("data[i].position");
    let _ = j_resp.string_of("data[i].parentId").unwrap_or_default();
    let _ = j_resp.string_of("data[i].mediaId").unwrap_or_default();
    let _ = j_resp.string_of("data[i].childrenCount").unwrap_or_default();
    let _ = j_resp.string_of("data[i].articleCount").unwrap_or_default();
    i = i + 1;
}