Sample code for 30+ languages & platforms
Rust

WiX Create Product

See more WiX Examples

Creates a new product.

Note: If you get a 403 error response, try refreshing the access token.

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 \
//    'https://www.wixapis.com/stores/v1/products' \
//     --data-binary '{
//                      "product": {
//                        "name": "T-shirt",
//                        "productType": "physical",
//                        "priceData": {
//                          "price": 10.5
//                        },
//                        "description": "nice summer t-shirt",
//                        "sku": "123df",
//                        "visible": false,
//                        "weight": 0.2,
//                        "discount": {
//                        	"type": "AMOUNT",
//                        	"value": 1
//                        },
//                        "manageVariants": true,
//                        "productOptions": [
//                          {
//                            "name": "Size",
//                            "choices": [
//                              {
//                                "value": "S",
//                                "description": "S"
//                              },
//                              {
//                                "value": "L",
//                                "description": "L"
//                              }
//                            ]
//                          }
//                        ]
//                      }
//                    }' \
//    -H 'Content-Type: application/json' \
//    -H 'Authorization: <AUTH>'

// Use the following online tool to generate HTTP code from a CURL command
// Convert a cURL Command to HTTP Source Code

// Use this online tool to generate code from sample JSON:
// Generate Code to Create JSON

// The following JSON is sent in the request body.

// {
//   "product": {
//     "name": "T-shirt",
//     "productType": "physical",
//     "priceData": {
//       "price": 10.5
//     },
//     "description": "nice summer t-shirt",
//     "sku": "123df",
//     "visible": false,
//     "weight": 0.2,
//     "discount": {
//       "type": "AMOUNT",
//       "value": 1
//     },
//     "manageVariants": true,
//     "productOptions": [
//       {
//         "name": "Size",
//         "choices": [
//           {
//             "value": "S",
//             "description": "S"
//           },
//           {
//             "value": "L",
//             "description": "L"
//           }
//         ]
//       }
//     ]
//   }
// }

let json = chilkat::JsonObject::new();
let _ = json.update_string("product.name", "T-shirt");
let _ = json.update_string("product.productType", "physical");
let _ = json.update_number("product.priceData.price", "10.5");
let _ = json.update_string("product.description", "nice summer t-shirt");
let _ = json.update_string("product.sku", "123df");
let _ = json.update_bool("product.visible", false);
let _ = json.update_number("product.weight", "0.2");
let _ = json.update_string("product.discount.type", "AMOUNT");
let _ = json.update_int("product.discount.value", 1);
let _ = json.update_bool("product.manageVariants", true);
let _ = json.update_string("product.productOptions[0].name", "Size");
let _ = json.update_string("product.productOptions[0].choices[0].value", "S");
let _ = json.update_string("product.productOptions[0].choices[0].description", "S");
let _ = json.update_string("product.productOptions[0].choices[1].value", "L");
let _ = json.update_string("product.productOptions[0].choices[1].description", "L");

http.set_auth_token("ACCESS_TOKEN");

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

// {
//   "product": {
//     "id": "e28e4ddd-6ed0-4098-a5e5-cf4bd9c4f7b5",
//     "name": "T-shirt",
//     "slug": "t-shirt-1",
//     "visible": false,
//     "productType": "physical",
//     "description": "nice summer t-shirt",
//     "stock": {
//       "trackInventory": false,
//       "inStock": true
//     },
//     "price": {
//       "currency": "ILS",
//       "price": 10.5,
//       "discountedPrice": 9.5,
//       "formatted": {
//         "price": "10.50",
//         "discountedPrice": "9.50"
//       }
//     },
//     "priceData": {
//       "currency": "ILS",
//       "price": 10.5,
//       "discountedPrice": 9.5,
//       "formatted": {
//         "price": "10.50",
//         "discountedPrice": "9.50"
//       }
//     },
//     "additionalInfoSections": [
//     ],
//     "ribbons": [
//     ],
//     "media": {
//       "items": [
//       ]
//     },
//     "customTextFields": [
//     ],
//     "manageVariants": true,
//     "productOptions": [
//       {
//         "optionType": "drop_down",
//         "name": "Size",
//         "choices": [
//           {
//             "value": "S",
//             "description": "S",
//             "inStock": true,
//             "visible": true
//           },
//           {
//             "value": "L",
//             "description": "L",
//             "inStock": true,
//             "visible": true
//           }
//         ]
//       }
//     ],
//     "productPageUrl": {
//       "base": "https://www.itsjusttooeasy123.com/",
//       "path": "/product-page/t-shirt-1"
//     },
//     "numericId": "1567588455405000",
//     "inventoryItemId": "1d71b222-912f-bf67-5a1a-30b4263b084a",
//     "discount": {
//       "type": "AMOUNT",
//       "value": 1
//     },
//     "collectionIds": [
//     ],
//     "variants": [
//       {
//         "id": "00000000-0000-0001-0005-93fc95e0514a",
//         "choices": {
//           "Size": "S"
//         },
//         "variant": {
//           "priceData": {
//             "currency": "ILS",
//             "price": 10.5,
//             "discountedPrice": 9.5,
//             "formatted": {
//               "price": "10.50",
//               "discountedPrice": "9.50"
//             }
//           },
//           "weight": 10,
//           "visible": true
//         }
//       },
//       {
//         "id": "00000000-0000-0002-0005-93fc95e0514a",
//         "choices": {
//           "Size": "L"
//         },
//         "variant": {
//           "priceData": {
//             "currency": "ILS",
//             "price": 10.5,
//             "discountedPrice": 9.5,
//             "formatted": {
//               "price": "10.50",
//               "discountedPrice": "9.50"
//             }
//           },
//           "visible": 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 mut j: i32 = 0;
let mut count_j: i32 = 0;

let product_id = j_resp.string_of("product.id").unwrap_or_default();
let product_name = j_resp.string_of("product.name").unwrap_or_default();
let product_slug = j_resp.string_of("product.slug").unwrap_or_default();
let product_visible = j_resp.bool_of("product.visible");
let product_product_type = j_resp.string_of("product.productType").unwrap_or_default();
let product_description = j_resp.string_of("product.description").unwrap_or_default();
let product_stock_track_inventory = j_resp.bool_of("product.stock.trackInventory");
let product_stock_in_stock = j_resp.bool_of("product.stock.inStock");
let product_price_currency = j_resp.string_of("product.price.currency").unwrap_or_default();
let product_price_price = j_resp.string_of("product.price.price").unwrap_or_default();
let product_price_discounted_price = j_resp.string_of("product.price.discountedPrice").unwrap_or_default();
let product_price_formatted_price = j_resp.string_of("product.price.formatted.price").unwrap_or_default();
let product_price_formatted_discounted_price = j_resp.string_of("product.price.formatted.discountedPrice").unwrap_or_default();
let product_price_data_currency = j_resp.string_of("product.priceData.currency").unwrap_or_default();
let product_price_data_price = j_resp.string_of("product.priceData.price").unwrap_or_default();
let product_price_data_discounted_price = j_resp.string_of("product.priceData.discountedPrice").unwrap_or_default();
let product_price_data_formatted_price = j_resp.string_of("product.priceData.formatted.price").unwrap_or_default();
let product_price_data_formatted_discounted_price = j_resp.string_of("product.priceData.formatted.discountedPrice").unwrap_or_default();
let product_manage_variants = j_resp.bool_of("product.manageVariants");
let product_product_page_url_base = j_resp.string_of("product.productPageUrl.base").unwrap_or_default();
let product_product_page_url_path = j_resp.string_of("product.productPageUrl.path").unwrap_or_default();
let product_numeric_id = j_resp.string_of("product.numericId").unwrap_or_default();
let product_inventory_item_id = j_resp.string_of("product.inventoryItemId").unwrap_or_default();
let product_discount_type = j_resp.string_of("product.discount.type").unwrap_or_default();
let product_discount_value = j_resp.int_of("product.discount.value");
let mut i = 0;
let mut count_i = j_resp.size_of_array("product.additionalInfoSections");
while i < count_i {
    j_resp.set_i(i);
    i = i + 1;
}

i = 0;
count_i = j_resp.size_of_array("product.ribbons");
while i < count_i {
    j_resp.set_i(i);
    i = i + 1;
}

i = 0;
count_i = j_resp.size_of_array("product.media.items");
while i < count_i {
    j_resp.set_i(i);
    i = i + 1;
}

i = 0;
count_i = j_resp.size_of_array("product.customTextFields");
while i < count_i {
    j_resp.set_i(i);
    i = i + 1;
}

i = 0;
count_i = j_resp.size_of_array("product.productOptions");
while i < count_i {
    j_resp.set_i(i);
    let _ = j_resp.string_of("product.productOptions[i].optionType").unwrap_or_default();
    let _ = j_resp.string_of("product.productOptions[i].name").unwrap_or_default();
    j = 0;
    count_j = j_resp.size_of_array("product.productOptions[i].choices");
    while j < count_j {
        j_resp.set_j(j);
        let _ = j_resp.string_of("product.productOptions[i].choices[j].value").unwrap_or_default();
        let _ = j_resp.string_of("product.productOptions[i].choices[j].description").unwrap_or_default();
        let _ = j_resp.bool_of("product.productOptions[i].choices[j].inStock");
        let _ = j_resp.bool_of("product.productOptions[i].choices[j].visible");
        j = j + 1;
    }

    i = i + 1;
}

i = 0;
count_i = j_resp.size_of_array("product.collectionIds");
while i < count_i {
    j_resp.set_i(i);
    i = i + 1;
}

i = 0;
count_i = j_resp.size_of_array("product.variants");
while i < count_i {
    j_resp.set_i(i);
    let _ = j_resp.string_of("product.variants[i].id").unwrap_or_default();
    let _ = j_resp.string_of("product.variants[i].choices.Size").unwrap_or_default();
    let _ = j_resp.string_of("product.variants[i].variant.priceData.currency").unwrap_or_default();
    let _ = j_resp.string_of("product.variants[i].variant.priceData.price").unwrap_or_default();
    let _ = j_resp.string_of("product.variants[i].variant.priceData.discountedPrice").unwrap_or_default();
    let _ = j_resp.string_of("product.variants[i].variant.priceData.formatted.price").unwrap_or_default();
    let _ = j_resp.string_of("product.variants[i].variant.priceData.formatted.discountedPrice").unwrap_or_default();
    let _ = j_resp.int_of("product.variants[i].variant.weight");
    let _ = j_resp.bool_of("product.variants[i].variant.visible");
    i = i + 1;
}