Sample code for 30+ languages & platforms
Swift

WiX - Get all Products in a Store

See more WiX Examples

Gets the first page of products in a store.

Chilkat Swift Downloads

Swift

func chilkatTest() {
    var success: Bool = false

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

    let http = CkoHttp()!

    // 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 = CkoJsonObject()!
    json.updateBool(jsonPath: "includeVariants", value: true)

    http.authToken = "ACCESS_TOKEN"

    let resp = CkoHttpResponse()!
    success = http.httpJson(verb: "POST", url: "https://www.wixapis.com/stores/v1/products/query", json: json, contentType: "application/json", response: resp)
    if success == false {
        print("\(http.lastErrorText!)")
        return
    }

    let sbResponseBody = CkoStringBuilder()!
    resp.getBodySb(sb: sbResponseBody)
    let jResp = CkoJsonObject()!
    jResp.loadSb(sb: sbResponseBody)
    jResp.emitCompact = false

    print("Response Body:")
    print("\(jResp.emit()!)")

    var respStatusCode: Int = resp.statusCode.intValue
    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: String?
    var name: String?
    var slug: String?
    var visible: Bool
    var productType: String?
    var description: String?
    var stockTrackInventory: Bool
    var stockQuantity: Int
    var stockInStock: Bool
    var priceCurrency: String?
    var pricePrice: Int
    var priceDiscountedPrice: Int
    var priceFormattedPrice: String?
    var priceFormattedDiscountedPrice: String?
    var priceDataCurrency: String?
    var priceDataPrice: Int
    var priceDataDiscountedPrice: Int
    var priceDataFormattedPrice: String?
    var priceDataFormattedDiscountedPrice: String?
    var manageVariants: Bool
    var productPageUrlBase: String?
    var productPageUrlPath: String?
    var numericId: String?
    var inventoryItemId: String?
    var discountType: String?
    var discountValue: Int
    var sku: String?
    var weight: Int
    var j: Int
    var count_j: Int
    var text: String?
    var strVal: String?

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

        j = 0
        count_j = jResp.size(ofArray: "products[i].ribbons").intValue
        while j < count_j {
            jResp.j = j
            text = jResp.string(of: "products[i].ribbons[j].text")
            j = j + 1
        }

        j = 0
        count_j = jResp.size(ofArray: "products[i].media.items").intValue
        while j < count_j {
            jResp.j = j
            j = j + 1
        }

        j = 0
        count_j = jResp.size(ofArray: "products[i].customTextFields").intValue
        while j < count_j {
            jResp.j = j
            j = j + 1
        }

        j = 0
        count_j = jResp.size(ofArray: "products[i].productOptions").intValue
        while j < count_j {
            jResp.j = j
            j = j + 1
        }

        j = 0
        count_j = jResp.size(ofArray: "products[i].collectionIds").intValue
        while j < count_j {
            jResp.j = j
            strVal = jResp.string(of: "products[i].collectionIds[j]")
            j = j + 1
        }

        j = 0
        count_j = jResp.size(ofArray: "products[i].variants").intValue
        while j < count_j {
            jResp.j = j
            j = j + 1
        }

        i = i + 1
    }


}