Sample code for 30+ languages & platforms
Unicode C++

WiX - Get all Products in a Store

See more WiX Examples

Gets the first page of products in a store.

Chilkat Unicode C++ Downloads

Unicode C++
#include <CkHttpW.h>
#include <CkJsonObjectW.h>
#include <CkHttpResponseW.h>
#include <CkStringBuilderW.h>

void ChilkatSample(void)
    {
    bool success = false;

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

    CkHttpW http;

    // Implements the following CURL command:

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

    CkJsonObjectW json;
    json.UpdateBool(L"includeVariants",true);

    http.put_AuthToken(L"ACCESS_TOKEN");

    CkHttpResponseW resp;
    success = http.HttpJson(L"POST",L"https://www.wixapis.com/stores/v1/products/query",json,L"application/json",resp);
    if (success == false) {
        wprintf(L"%s\n",http.lastErrorText());
        return;
    }

    CkStringBuilderW sbResponseBody;
    resp.GetBodySb(sbResponseBody);
    CkJsonObjectW jResp;
    jResp.LoadSb(sbResponseBody);
    jResp.put_EmitCompact(false);

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

    int respStatusCode = resp.get_StatusCode();
    wprintf(L"Response Status Code = %d\n",respStatusCode);
    if (respStatusCode >= 400) {
        wprintf(L"Response Header:\n");
        wprintf(L"%s\n",resp.header());
        wprintf(L"Failed.\n");
        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

    // 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.

    const wchar_t *id = 0;
    const wchar_t *name = 0;
    const wchar_t *slug = 0;
    bool visible;
    const wchar_t *productType = 0;
    const wchar_t *description = 0;
    bool stockTrackInventory;
    int stockQuantity;
    bool stockInStock;
    const wchar_t *priceCurrency = 0;
    int pricePrice;
    int priceDiscountedPrice;
    const wchar_t *priceFormattedPrice = 0;
    const wchar_t *priceFormattedDiscountedPrice = 0;
    const wchar_t *priceDataCurrency = 0;
    int priceDataPrice;
    int priceDataDiscountedPrice;
    const wchar_t *priceDataFormattedPrice = 0;
    const wchar_t *priceDataFormattedDiscountedPrice = 0;
    bool manageVariants;
    const wchar_t *productPageUrlBase = 0;
    const wchar_t *productPageUrlPath = 0;
    const wchar_t *numericId = 0;
    const wchar_t *inventoryItemId = 0;
    const wchar_t *discountType = 0;
    int discountValue;
    const wchar_t *sku = 0;
    int weight;
    int j;
    int count_j;
    const wchar_t *text = 0;
    const wchar_t *strVal = 0;

    int metadataItems = jResp.IntOf(L"metadata.items");
    int metadataOffset = jResp.IntOf(L"metadata.offset");
    int totalResults = jResp.IntOf(L"totalResults");
    int i = 0;
    int count_i = jResp.SizeOfArray(L"products");
    while (i < count_i) {
        jResp.put_I(i);
        id = jResp.stringOf(L"products[i].id");
        name = jResp.stringOf(L"products[i].name");
        slug = jResp.stringOf(L"products[i].slug");
        visible = jResp.BoolOf(L"products[i].visible");
        productType = jResp.stringOf(L"products[i].productType");
        description = jResp.stringOf(L"products[i].description");
        stockTrackInventory = jResp.BoolOf(L"products[i].stock.trackInventory");
        stockQuantity = jResp.IntOf(L"products[i].stock.quantity");
        stockInStock = jResp.BoolOf(L"products[i].stock.inStock");
        priceCurrency = jResp.stringOf(L"products[i].price.currency");
        pricePrice = jResp.IntOf(L"products[i].price.price");
        priceDiscountedPrice = jResp.IntOf(L"products[i].price.discountedPrice");
        priceFormattedPrice = jResp.stringOf(L"products[i].price.formatted.price");
        priceFormattedDiscountedPrice = jResp.stringOf(L"products[i].price.formatted.discountedPrice");
        priceDataCurrency = jResp.stringOf(L"products[i].priceData.currency");
        priceDataPrice = jResp.IntOf(L"products[i].priceData.price");
        priceDataDiscountedPrice = jResp.IntOf(L"products[i].priceData.discountedPrice");
        priceDataFormattedPrice = jResp.stringOf(L"products[i].priceData.formatted.price");
        priceDataFormattedDiscountedPrice = jResp.stringOf(L"products[i].priceData.formatted.discountedPrice");
        manageVariants = jResp.BoolOf(L"products[i].manageVariants");
        productPageUrlBase = jResp.stringOf(L"products[i].productPageUrl.base");
        productPageUrlPath = jResp.stringOf(L"products[i].productPageUrl.path");
        numericId = jResp.stringOf(L"products[i].numericId");
        inventoryItemId = jResp.stringOf(L"products[i].inventoryItemId");
        discountType = jResp.stringOf(L"products[i].discount.type");
        discountValue = jResp.IntOf(L"products[i].discount.value");
        sku = jResp.stringOf(L"products[i].sku");
        weight = jResp.IntOf(L"products[i].weight");
        j = 0;
        count_j = jResp.SizeOfArray(L"products[i].additionalInfoSections");
        while (j < count_j) {
            jResp.put_J(j);
            j = j + 1;
        }

        j = 0;
        count_j = jResp.SizeOfArray(L"products[i].ribbons");
        while (j < count_j) {
            jResp.put_J(j);
            text = jResp.stringOf(L"products[i].ribbons[j].text");
            j = j + 1;
        }

        j = 0;
        count_j = jResp.SizeOfArray(L"products[i].media.items");
        while (j < count_j) {
            jResp.put_J(j);
            j = j + 1;
        }

        j = 0;
        count_j = jResp.SizeOfArray(L"products[i].customTextFields");
        while (j < count_j) {
            jResp.put_J(j);
            j = j + 1;
        }

        j = 0;
        count_j = jResp.SizeOfArray(L"products[i].productOptions");
        while (j < count_j) {
            jResp.put_J(j);
            j = j + 1;
        }

        j = 0;
        count_j = jResp.SizeOfArray(L"products[i].collectionIds");
        while (j < count_j) {
            jResp.put_J(j);
            strVal = jResp.stringOf(L"products[i].collectionIds[j]");
            j = j + 1;
        }

        j = 0;
        count_j = jResp.SizeOfArray(L"products[i].variants");
        while (j < count_j) {
            jResp.put_J(j);
            j = j + 1;
        }

        i = i + 1;
    }
    }