Sample code for 30+ languages & platforms
Rust

Shopware List Media

See more Shopware Examples

Demonstrates how to get a list of media in Shopware.

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/media?limit=10", &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": 6708,
//       "albumId": -9,
//       "name": "sonnenblume",
//       "description": "",
//       "path": "https:\/\/my-shopware-shop.com\/media\/pdf\/2f\/26\/52\/sonnenblume.zip",
//       "type": "ARCHIVE",
//       "extension": "zip",
//       "userId": 5,
//       "created": "2021-03-01T00:00:00+0100",
//       "fileSize": 216905,
//       "width": null,
//       "height": null,
//       "attribute": null
//     },
//     {
//       "id": 6709,
//       "albumId": -9,
//       "name": "csinventur_anleitung",
//       "description": "",
//       "path": "https:\/\/my-shopware-shop.com\/media\/pdf\/19\/21\/86\/csinventur_anleitung.pdf",
//       "type": "PDF",
//       "extension": "pdf",
//       "userId": 5,
//       "created": "2021-03-01T00:00:00+0100",
//       "fileSize": 837131,
//       "width": null,
//       "height": null,
//       "attribute": null
//     },
//     {
//       "id": 6710,
//       "albumId": -9,
//       "name": "photos_fre_carousel_elevatorpitch_620x252",
//       "description": "",
//       "path": "https:\/\/my-shopware-shop.com\/media\/pdf\/d8\/d7\/b4\/photos_fre_carousel_elevatorpitch_620x252.mp4",
//       "type": "VIDEO",
//       "extension": "mp4",
//       "userId": 5,
//       "created": "2021-03-01T00:00:00+0100",
//       "fileSize": 2499157,
//       "width": null,
//       "height": null,
//       "attribute": null
//     },
// 
// 	...
//   ],
//   "total": 31,
//   "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.int_of("data[i].albumId");
    let _ = j_resp.string_of("data[i].name").unwrap_or_default();
    let _ = j_resp.string_of("data[i].description").unwrap_or_default();
    let _ = j_resp.string_of("data[i].path").unwrap_or_default();
    let _ = j_resp.string_of("data[i].type").unwrap_or_default();
    let _ = j_resp.string_of("data[i].extension").unwrap_or_default();
    let _ = j_resp.int_of("data[i].userId");
    let _ = j_resp.string_of("data[i].created").unwrap_or_default();
    let _ = j_resp.int_of("data[i].fileSize");
    let _ = j_resp.string_of("data[i].width").unwrap_or_default();
    let _ = j_resp.string_of("data[i].height").unwrap_or_default();
    let _ = j_resp.string_of("data[i].attribute").unwrap_or_default();
    i = i + 1;
}