Sample code for 30+ languages & platforms
Unicode C

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 Unicode C Downloads

Unicode C
#include <C_CkHttpW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkHttpResponseW.h>
#include <C_CkStringBuilderW.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkHttpW http;
    HCkJsonObjectW json;
    HCkHttpResponseW resp;
    HCkStringBuilderW sbResponseBody;
    HCkJsonObjectW jResp;
    int respStatusCode;
    const wchar_t *optionType;
    const wchar_t *name;
    int j;
    int count_j;
    const wchar_t *value;
    const wchar_t *description;
    BOOL inStock;
    BOOL visible;
    const wchar_t *id;
    const wchar_t *choicesSize;
    const wchar_t *variantPriceDataCurrency;
    const wchar_t *variantPriceDataPrice;
    const wchar_t *variantPriceDataDiscountedPrice;
    const wchar_t *variantPriceDataFormattedPrice;
    const wchar_t *variantPriceDataFormattedDiscountedPrice;
    int variantWeight;
    BOOL variantVisible;
    const wchar_t *productId;
    const wchar_t *productName;
    const wchar_t *productSlug;
    BOOL productVisible;
    const wchar_t *productProductType;
    const wchar_t *productDescription;
    BOOL productStockTrackInventory;
    BOOL productStockInStock;
    const wchar_t *productPriceCurrency;
    const wchar_t *productPricePrice;
    const wchar_t *productPriceDiscountedPrice;
    const wchar_t *productPriceFormattedPrice;
    const wchar_t *productPriceFormattedDiscountedPrice;
    const wchar_t *productPriceDataCurrency;
    const wchar_t *productPriceDataPrice;
    const wchar_t *productPriceDataDiscountedPrice;
    const wchar_t *productPriceDataFormattedPrice;
    const wchar_t *productPriceDataFormattedDiscountedPrice;
    BOOL productManageVariants;
    const wchar_t *productProductPageUrlBase;
    const wchar_t *productProductPageUrlPath;
    const wchar_t *productNumericId;
    const wchar_t *productInventoryItemId;
    const wchar_t *productDiscountType;
    int productDiscountValue;
    int i;
    int count_i;

    success = FALSE;

    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    http = CkHttpW_Create();

    // 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"
    //           }
    //         ]
    //       }
    //     ]
    //   }
    // }

    json = CkJsonObjectW_Create();
    CkJsonObjectW_UpdateString(json,L"product.name",L"T-shirt");
    CkJsonObjectW_UpdateString(json,L"product.productType",L"physical");
    CkJsonObjectW_UpdateNumber(json,L"product.priceData.price",L"10.5");
    CkJsonObjectW_UpdateString(json,L"product.description",L"nice summer t-shirt");
    CkJsonObjectW_UpdateString(json,L"product.sku",L"123df");
    CkJsonObjectW_UpdateBool(json,L"product.visible",FALSE);
    CkJsonObjectW_UpdateNumber(json,L"product.weight",L"0.2");
    CkJsonObjectW_UpdateString(json,L"product.discount.type",L"AMOUNT");
    CkJsonObjectW_UpdateInt(json,L"product.discount.value",1);
    CkJsonObjectW_UpdateBool(json,L"product.manageVariants",TRUE);
    CkJsonObjectW_UpdateString(json,L"product.productOptions[0].name",L"Size");
    CkJsonObjectW_UpdateString(json,L"product.productOptions[0].choices[0].value",L"S");
    CkJsonObjectW_UpdateString(json,L"product.productOptions[0].choices[0].description",L"S");
    CkJsonObjectW_UpdateString(json,L"product.productOptions[0].choices[1].value",L"L");
    CkJsonObjectW_UpdateString(json,L"product.productOptions[0].choices[1].description",L"L");

    CkHttpW_putAuthToken(http,L"ACCESS_TOKEN");

    resp = CkHttpResponseW_Create();
    success = CkHttpW_HttpJson(http,L"POST",L"https://www.wixapis.com/stores/v1/products",json,L"application/json",resp);
    if (success == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(json);
        CkHttpResponseW_Dispose(resp);
        return;
    }

    sbResponseBody = CkStringBuilderW_Create();
    CkHttpResponseW_GetBodySb(resp,sbResponseBody);
    jResp = CkJsonObjectW_Create();
    CkJsonObjectW_LoadSb(jResp,sbResponseBody);
    CkJsonObjectW_putEmitCompact(jResp,FALSE);

    wprintf(L"Response Body:\n");
    wprintf(L"%s\n",CkJsonObjectW_emit(jResp));

    respStatusCode = CkHttpResponseW_getStatusCode(resp);
    wprintf(L"Response Status Code = %d\n",respStatusCode);
    if (respStatusCode >= 400) {
        wprintf(L"Response Header:\n");
        wprintf(L"%s\n",CkHttpResponseW_header(resp));
        wprintf(L"Failed.\n");
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(json);
        CkHttpResponseW_Dispose(resp);
        CkStringBuilderW_Dispose(sbResponseBody);
        CkJsonObjectW_Dispose(jResp);
        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

    // Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.
    // See this example explaining how this memory should be used: const char * functions.

    productId = CkJsonObjectW_stringOf(jResp,L"product.id");
    productName = CkJsonObjectW_stringOf(jResp,L"product.name");
    productSlug = CkJsonObjectW_stringOf(jResp,L"product.slug");
    productVisible = CkJsonObjectW_BoolOf(jResp,L"product.visible");
    productProductType = CkJsonObjectW_stringOf(jResp,L"product.productType");
    productDescription = CkJsonObjectW_stringOf(jResp,L"product.description");
    productStockTrackInventory = CkJsonObjectW_BoolOf(jResp,L"product.stock.trackInventory");
    productStockInStock = CkJsonObjectW_BoolOf(jResp,L"product.stock.inStock");
    productPriceCurrency = CkJsonObjectW_stringOf(jResp,L"product.price.currency");
    productPricePrice = CkJsonObjectW_stringOf(jResp,L"product.price.price");
    productPriceDiscountedPrice = CkJsonObjectW_stringOf(jResp,L"product.price.discountedPrice");
    productPriceFormattedPrice = CkJsonObjectW_stringOf(jResp,L"product.price.formatted.price");
    productPriceFormattedDiscountedPrice = CkJsonObjectW_stringOf(jResp,L"product.price.formatted.discountedPrice");
    productPriceDataCurrency = CkJsonObjectW_stringOf(jResp,L"product.priceData.currency");
    productPriceDataPrice = CkJsonObjectW_stringOf(jResp,L"product.priceData.price");
    productPriceDataDiscountedPrice = CkJsonObjectW_stringOf(jResp,L"product.priceData.discountedPrice");
    productPriceDataFormattedPrice = CkJsonObjectW_stringOf(jResp,L"product.priceData.formatted.price");
    productPriceDataFormattedDiscountedPrice = CkJsonObjectW_stringOf(jResp,L"product.priceData.formatted.discountedPrice");
    productManageVariants = CkJsonObjectW_BoolOf(jResp,L"product.manageVariants");
    productProductPageUrlBase = CkJsonObjectW_stringOf(jResp,L"product.productPageUrl.base");
    productProductPageUrlPath = CkJsonObjectW_stringOf(jResp,L"product.productPageUrl.path");
    productNumericId = CkJsonObjectW_stringOf(jResp,L"product.numericId");
    productInventoryItemId = CkJsonObjectW_stringOf(jResp,L"product.inventoryItemId");
    productDiscountType = CkJsonObjectW_stringOf(jResp,L"product.discount.type");
    productDiscountValue = CkJsonObjectW_IntOf(jResp,L"product.discount.value");
    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"product.additionalInfoSections");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"product.ribbons");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"product.media.items");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"product.customTextFields");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"product.productOptions");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        optionType = CkJsonObjectW_stringOf(jResp,L"product.productOptions[i].optionType");
        name = CkJsonObjectW_stringOf(jResp,L"product.productOptions[i].name");
        j = 0;
        count_j = CkJsonObjectW_SizeOfArray(jResp,L"product.productOptions[i].choices");
        while (j < count_j) {
            CkJsonObjectW_putJ(jResp,j);
            value = CkJsonObjectW_stringOf(jResp,L"product.productOptions[i].choices[j].value");
            description = CkJsonObjectW_stringOf(jResp,L"product.productOptions[i].choices[j].description");
            inStock = CkJsonObjectW_BoolOf(jResp,L"product.productOptions[i].choices[j].inStock");
            visible = CkJsonObjectW_BoolOf(jResp,L"product.productOptions[i].choices[j].visible");
            j = j + 1;
        }

        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"product.collectionIds");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"product.variants");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        id = CkJsonObjectW_stringOf(jResp,L"product.variants[i].id");
        choicesSize = CkJsonObjectW_stringOf(jResp,L"product.variants[i].choices.Size");
        variantPriceDataCurrency = CkJsonObjectW_stringOf(jResp,L"product.variants[i].variant.priceData.currency");
        variantPriceDataPrice = CkJsonObjectW_stringOf(jResp,L"product.variants[i].variant.priceData.price");
        variantPriceDataDiscountedPrice = CkJsonObjectW_stringOf(jResp,L"product.variants[i].variant.priceData.discountedPrice");
        variantPriceDataFormattedPrice = CkJsonObjectW_stringOf(jResp,L"product.variants[i].variant.priceData.formatted.price");
        variantPriceDataFormattedDiscountedPrice = CkJsonObjectW_stringOf(jResp,L"product.variants[i].variant.priceData.formatted.discountedPrice");
        variantWeight = CkJsonObjectW_IntOf(jResp,L"product.variants[i].variant.weight");
        variantVisible = CkJsonObjectW_BoolOf(jResp,L"product.variants[i].variant.visible");
        i = i + 1;
    }



    CkHttpW_Dispose(http);
    CkJsonObjectW_Dispose(json);
    CkHttpResponseW_Dispose(resp);
    CkStringBuilderW_Dispose(sbResponseBody);
    CkJsonObjectW_Dispose(jResp);

    }