Rust
Rust
Shopify Get all products, showing only some attributes
See more Shopify Examples
Get all products, showing only some attributesChilkat Rust Downloads
let rest = chilkat::Rest::new();
let _ = rest.set_auth_basic("SHOPIFY_PRIVATE_API_KEY", "SHOPIFY_PRIVATE_API_KEY");
if rest.connect("chilkat.myshopify.com", 443, true, true).is_err() {
println!("{}", rest.last_error_text());
return;
}
let sb_json = chilkat::StringBuilder::new();
if rest.full_request_no_body_sb("GET", "/admin/products.json?fields=id,images,title", &sb_json).is_err() {
println!("{}", rest.last_error_text());
return;
}
if rest.response_status_code() != 200 {
println!("Received error response code: {}", rest.response_status_code());
println!("Response body:");
println!("{}", sb_json.get_as_string().unwrap_or_default());
return;
}
let json = chilkat::JsonObject::new();
let _ = json.load_sb(&sb_json);
// The following code parses the JSON response.
// A sample JSON response is shown below the sample code.
let mut i: i32 = 0;
let mut j: i32 = 0;
let mut count_j: i32 = 0;
let mut k: i32 = 0;
let mut count_k: i32 = 0;
i = 0;
let count_i = json.size_of_array("products");
while i < count_i {
json.set_i(i);
let _ = json.int_of("products[i].id");
let _ = json.string_of("products[i].title").unwrap_or_default();
j = 0;
count_j = json.size_of_array("products[i].images");
while j < count_j {
json.set_j(j);
let _ = json.int_of("products[i].images[j].id");
let _ = json.int_of("products[i].images[j].product_id");
let _ = json.int_of("products[i].images[j].position");
let _ = json.string_of("products[i].images[j].created_at").unwrap_or_default();
let _ = json.string_of("products[i].images[j].updated_at").unwrap_or_default();
let _ = json.int_of("products[i].images[j].width");
let _ = json.int_of("products[i].images[j].height");
let _ = json.string_of("products[i].images[j].src").unwrap_or_default();
k = 0;
count_k = json.size_of_array("products[i].images[j].variant_ids");
while k < count_k {
json.set_k(k);
let _ = json.int_of("products[i].images[j].variant_ids[k]");
k = k + 1;
}
j = j + 1;
}
i = i + 1;
}
// A sample JSON response body that is parsed by the above code:
// {
// "products": [
// {
// "id": 632910392,
// "title": "IPod Nano - 8GB",
// "images": [
// {
// "id": 850703190,
// "product_id": 632910392,
// "position": 1,
// "created_at": "2017-09-22T14:08:02-04:00",
// "updated_at": "2017-09-22T14:08:02-04:00",
// "width": 123,
// "height": 456,
// "src": "https:\/\/cdn.shopify.com\/s\/files\/1\/0006\/9093\/3842\/products\/ipod-nano.png?v=1506103682",
// "variant_ids": [
// ]
// },
// {
// "id": 562641783,
// "product_id": 632910392,
// "position": 2,
// "created_at": "2017-09-22T14:08:02-04:00",
// "updated_at": "2017-09-22T14:08:02-04:00",
// "width": 123,
// "height": 456,
// "src": "https:\/\/cdn.shopify.com\/s\/files\/1\/0006\/9093\/3842\/products\/ipod-nano-2.png?v=1506103682",
// "variant_ids": [
// 808950810
// ]
// }
// ]
// },
// {
// "id": 921728736,
// "title": "IPod Touch 8GB",
// "images": [
// ]
// }
// ]
// }
println!("Example Completed.");