Sample code for 30+ languages & platforms
Rust

WiX - Get all Products in a Store

See more WiX Examples

Gets the first page of products in a store.

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

// Implements the following CURL command:

// curl -X POST -H "Content-Type: application/json" \
//    -d '{
//   "includeVariants": true
//   }' https://www.wixapis.com/stores/v1/products/query

let json = chilkat::JsonObject::new();
let _ = json.update_bool("includeVariants", true);

http.set_auth_token("ACCESS_TOKEN");

let resp = chilkat::HttpResponse::new();
if http.http_json("POST", "https://www.wixapis.com/stores/v1/products/query", &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);

println!("Response Body:");
println!("{}", j_resp.emit().unwrap_or_default());

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;
}

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

// {
//   "products": [
//     {
//       "id": "58fcbb51-ff87-08ff-d97b-646726676e4a",
//       "name": "webhook test",
//       "slug": "webhook-test",
//       "visible": true,
//       "productType": "physical",
//       "description": "<p>fasdf<\/p>",
//       "stock": {
//         "trackInventory": true,
//         "quantity": 0,
//         "inStock": false
//       },
//       "price": {
//         "currency": "ILS",
//         "price": 234,
//         "discountedPrice": 234,
//         "formatted": {
//           "price": "234.00 ₪",
//           "discountedPrice": "234.00 ₪"
//         }
//       },
//       "priceData": {
//         "currency": "ILS",
//         "price": 234,
//         "discountedPrice": 234,
//         "formatted": {
//           "price": "234.00 ₪",
//           "discountedPrice": "234.00 ₪"
//         }
//       },
//       "additionalInfoSections": [
//       ],
//       "ribbons": [
//         {
//           "text": "ribby"
//         }
//       ],
//       "media": {
//         "items": [
//         ]
//       },
//       "customTextFields": [
//       ],
//       "manageVariants": true,
//       "productOptions": [
//       ],
//       "productPageUrl": {
//         "base": "https://www.my-website.com/",
//         "path": "/product-page/webhook-test"
//       },
//       "numericId": "1567078000586000",
//       "inventoryItemId": "a70344ae-0078-f700-2684-9b98d99891b5",
//       "discount": {
//         "type": "NONE",
//         "value": 0
//       },
//       "collectionIds": [
//       ],
//       "variants": [
//       ]
//     },
//     {
//       "id": "6507fd67-94e5-10af-73e4-d2167852d5bc",
//       "name": "digital product",
//       "slug": "digital-product",
//       "visible": true,
//       "productType": "digital",
//       "description": "",
//       "sku": "",
//       "weight": 0,
//       "stock": {
//         "trackInventory": false,
//         "inStock": true
//       },
//       "price": {
//         "currency": "ILS",
//         "price": 123,
//         "discountedPrice": 123,
//         "formatted": {
//           "price": "123.00 ₪",
//           "discountedPrice": "123.00 ₪"
//         }
//       },
//       "priceData": {
//         "currency": "ILS",
//         "price": 123,
//         "discountedPrice": 123,
//         "formatted": {
//           "price": "123.00 ₪",
//           "discountedPrice": "123.00 ₪"
//         }
//       },
//       "additionalInfoSections": [
//       ],
//       "ribbons": [
//       ],
//       "media": {
//         "items": [
//         ]
//       },
//       "customTextFields": [
//       ],
//       "manageVariants": false,
//       "productOptions": [
//       ],
//       "productPageUrl": {
//         "base": "https://www.my-website.com/",
//         "path": "/product-page/digital-product"
//       },
//       "numericId": "1544009414325000",
//       "inventoryItemId": "9af80298-6b1a-ef50-8c1b-2de987ad2a43",
//       "discount": {
//         "type": "NONE",
//         "value": 0
//       },
//       "collectionIds": [
//         "ae886d55-2572-eee8-b2c4-13219844b5e4"
//       ],
//       "variants": [
//       ]
//     }
//   ],
//   "metadata": {
//     "items": 100,
//     "offset": 0
//   },
//   "totalResults": 2
// }

// 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 mut j: i32 = 0;
let mut count_j: i32 = 0;

let metadata_items = j_resp.int_of("metadata.items");
let metadata_offset = j_resp.int_of("metadata.offset");
let total_results = j_resp.int_of("totalResults");
let mut i = 0;
let count_i = j_resp.size_of_array("products");
while i < count_i {
    j_resp.set_i(i);
    let _ = j_resp.string_of("products[i].id").unwrap_or_default();
    let _ = j_resp.string_of("products[i].name").unwrap_or_default();
    let _ = j_resp.string_of("products[i].slug").unwrap_or_default();
    let _ = j_resp.bool_of("products[i].visible");
    let _ = j_resp.string_of("products[i].productType").unwrap_or_default();
    let _ = j_resp.string_of("products[i].description").unwrap_or_default();
    let _ = j_resp.bool_of("products[i].stock.trackInventory");
    let _ = j_resp.int_of("products[i].stock.quantity");
    let _ = j_resp.bool_of("products[i].stock.inStock");
    let _ = j_resp.string_of("products[i].price.currency").unwrap_or_default();
    let _ = j_resp.int_of("products[i].price.price");
    let _ = j_resp.int_of("products[i].price.discountedPrice");
    let _ = j_resp.string_of("products[i].price.formatted.price").unwrap_or_default();
    let _ = j_resp.string_of("products[i].price.formatted.discountedPrice").unwrap_or_default();
    let _ = j_resp.string_of("products[i].priceData.currency").unwrap_or_default();
    let _ = j_resp.int_of("products[i].priceData.price");
    let _ = j_resp.int_of("products[i].priceData.discountedPrice");
    let _ = j_resp.string_of("products[i].priceData.formatted.price").unwrap_or_default();
    let _ = j_resp.string_of("products[i].priceData.formatted.discountedPrice").unwrap_or_default();
    let _ = j_resp.bool_of("products[i].manageVariants");
    let _ = j_resp.string_of("products[i].productPageUrl.base").unwrap_or_default();
    let _ = j_resp.string_of("products[i].productPageUrl.path").unwrap_or_default();
    let _ = j_resp.string_of("products[i].numericId").unwrap_or_default();
    let _ = j_resp.string_of("products[i].inventoryItemId").unwrap_or_default();
    let _ = j_resp.string_of("products[i].discount.type").unwrap_or_default();
    let _ = j_resp.int_of("products[i].discount.value");
    let _ = j_resp.string_of("products[i].sku").unwrap_or_default();
    let _ = j_resp.int_of("products[i].weight");
    j = 0;
    count_j = j_resp.size_of_array("products[i].additionalInfoSections");
    while j < count_j {
        j_resp.set_j(j);
        j = j + 1;
    }

    j = 0;
    count_j = j_resp.size_of_array("products[i].ribbons");
    while j < count_j {
        j_resp.set_j(j);
        let _ = j_resp.string_of("products[i].ribbons[j].text").unwrap_or_default();
        j = j + 1;
    }

    j = 0;
    count_j = j_resp.size_of_array("products[i].media.items");
    while j < count_j {
        j_resp.set_j(j);
        j = j + 1;
    }

    j = 0;
    count_j = j_resp.size_of_array("products[i].customTextFields");
    while j < count_j {
        j_resp.set_j(j);
        j = j + 1;
    }

    j = 0;
    count_j = j_resp.size_of_array("products[i].productOptions");
    while j < count_j {
        j_resp.set_j(j);
        j = j + 1;
    }

    j = 0;
    count_j = j_resp.size_of_array("products[i].collectionIds");
    while j < count_j {
        j_resp.set_j(j);
        let _ = j_resp.string_of("products[i].collectionIds[j]").unwrap_or_default();
        j = j + 1;
    }

    j = 0;
    count_j = j_resp.size_of_array("products[i].variants");
    while j < count_j {
        j_resp.set_j(j);
        j = j + 1;
    }

    i = i + 1;
}