Sample code for 30+ languages & platforms
Dart

WiX - Get all Products in a Store

See more WiX Examples

Gets the first page of products in a store.

Chilkat Dart Downloads

Dart
import 'package:chilkat/chilkat.dart';

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

  final http = CkHttp();

  // Implements the following CURL command:

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

  final json = CkJsonObject();
  json.updateBool('includeVariants', true);

  http.authToken = 'ACCESS_TOKEN';

  final resp = CkHttpResponse();
  try {
    http.httpJson('POST', 'https://www.wixapis.com/stores/v1/products/query', json, 'application/json', resp);
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  final sbResponseBody = CkStringBuilder();
  resp.getBodySb(sbResponseBody);
  final jResp = CkJsonObject();
  jResp.loadSb(sbResponseBody);
  jResp.emitCompact = false;

  print('Response Body:');
  print(jResp.emit());

  final respStatusCode = resp.statusCode;
  print('Response Status Code = $respStatusCode');
  if (respStatusCode >= 400) {
    print('Response Header:');
    print(resp.header);
    print('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

  var id = '';
  var name = '';
  var slug = '';
  var productType = '';
  var description = '';
  var stockQuantity = 0;
  var priceCurrency = '';
  var pricePrice = 0;
  var priceDiscountedPrice = 0;
  var priceFormattedPrice = '';
  var priceFormattedDiscountedPrice = '';
  var priceDataCurrency = '';
  var priceDataPrice = 0;
  var priceDataDiscountedPrice = 0;
  var priceDataFormattedPrice = '';
  var priceDataFormattedDiscountedPrice = '';
  var productPageUrlBase = '';
  var productPageUrlPath = '';
  var numericId = '';
  var inventoryItemId = '';
  var discountType = '';
  var discountValue = 0;
  var sku = '';
  var weight = 0;
  var j = 0;
  var countJ = 0;
  var text = '';
  var strVal = '';

  final metadataItems = jResp.intOf('metadata.items');
  final metadataOffset = jResp.intOf('metadata.offset');
  final totalResults = jResp.intOf('totalResults');
  var i = 0;
  final countI = jResp.sizeOfArray('products');
  while (i < countI) {
    jResp.i = i;
    id = jResp.stringOf('products[i].id');
    name = jResp.stringOf('products[i].name');
    slug = jResp.stringOf('products[i].slug');
    jResp.boolOf('products[i].visible');
    productType = jResp.stringOf('products[i].productType');
    description = jResp.stringOf('products[i].description');
    jResp.boolOf('products[i].stock.trackInventory');
    stockQuantity = jResp.intOf('products[i].stock.quantity');
    jResp.boolOf('products[i].stock.inStock');
    priceCurrency = jResp.stringOf('products[i].price.currency');
    pricePrice = jResp.intOf('products[i].price.price');
    priceDiscountedPrice = jResp.intOf('products[i].price.discountedPrice');
    priceFormattedPrice = jResp.stringOf('products[i].price.formatted.price');
    priceFormattedDiscountedPrice = jResp.stringOf('products[i].price.formatted.discountedPrice');
    priceDataCurrency = jResp.stringOf('products[i].priceData.currency');
    priceDataPrice = jResp.intOf('products[i].priceData.price');
    priceDataDiscountedPrice = jResp.intOf('products[i].priceData.discountedPrice');
    priceDataFormattedPrice = jResp.stringOf('products[i].priceData.formatted.price');
    priceDataFormattedDiscountedPrice = jResp.stringOf('products[i].priceData.formatted.discountedPrice');
    jResp.boolOf('products[i].manageVariants');
    productPageUrlBase = jResp.stringOf('products[i].productPageUrl.base');
    productPageUrlPath = jResp.stringOf('products[i].productPageUrl.path');
    numericId = jResp.stringOf('products[i].numericId');
    inventoryItemId = jResp.stringOf('products[i].inventoryItemId');
    discountType = jResp.stringOf('products[i].discount.type');
    discountValue = jResp.intOf('products[i].discount.value');
    sku = jResp.stringOf('products[i].sku');
    weight = jResp.intOf('products[i].weight');
    j = 0;
    countJ = jResp.sizeOfArray('products[i].additionalInfoSections');
    while (j < countJ) {
      jResp.j = j;
      j++;
    }

    j = 0;
    countJ = jResp.sizeOfArray('products[i].ribbons');
    while (j < countJ) {
      jResp.j = j;
      text = jResp.stringOf('products[i].ribbons[j].text');
      j++;
    }

    j = 0;
    countJ = jResp.sizeOfArray('products[i].media.items');
    while (j < countJ) {
      jResp.j = j;
      j++;
    }

    j = 0;
    countJ = jResp.sizeOfArray('products[i].customTextFields');
    while (j < countJ) {
      jResp.j = j;
      j++;
    }

    j = 0;
    countJ = jResp.sizeOfArray('products[i].productOptions');
    while (j < countJ) {
      jResp.j = j;
      j++;
    }

    j = 0;
    countJ = jResp.sizeOfArray('products[i].collectionIds');
    while (j < countJ) {
      jResp.j = j;
      strVal = jResp.stringOf('products[i].collectionIds[j]');
      j++;
    }

    j = 0;
    countJ = jResp.sizeOfArray('products[i].variants');
    while (j < countJ) {
      jResp.j = j;
      j++;
    }

    i++;
  }
}