Lua
Lua
WiX - Get all Products in a Store
See more WiX Examples
Gets the first page of products in a store.Chilkat Lua Downloads
local chilkat = require("chilkat")
-- This example assumes the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
local http = chilkat.Http.new()
-- Implements the following CURL command:
-- curl -X POST -H "Content-Type: application/json" \
-- -d '{
-- "includeVariants": true
-- }' https://www.wixapis.com/stores/v1/products/query
local json = chilkat.JsonObject.new()
json:update_bool("includeVariants", true)
http.auth_token = "ACCESS_TOKEN"
local resp = chilkat.HttpResponse.new()
local success = http:http_json("POST", "https://www.wixapis.com/stores/v1/products/query", json, "application/json", resp)
if not success then
print(http.last_error_text)
return
end
local sbResponseBody = chilkat.StringBuilder.new()
resp:get_body_sb(sbResponseBody)
local jResp = chilkat.JsonObject.new()
jResp:load_sb(sbResponseBody)
jResp.emit_compact = false
print("Response Body:")
print(jResp:emit())
local respStatusCode = resp.status_code
print("Response Status Code = " .. respStatusCode)
if respStatusCode >= 400 then
print("Response Header:")
print(resp.header)
print("Failed.")
return
end
-- 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
local id = ""
local name = ""
local slug = ""
local visible = false
local productType = ""
local description = ""
local stockTrackInventory = false
local stockQuantity = 0
local stockInStock = false
local priceCurrency = ""
local pricePrice = 0
local priceDiscountedPrice = 0
local priceFormattedPrice = ""
local priceFormattedDiscountedPrice = ""
local priceDataCurrency = ""
local priceDataPrice = 0
local priceDataDiscountedPrice = 0
local priceDataFormattedPrice = ""
local priceDataFormattedDiscountedPrice = ""
local manageVariants = false
local productPageUrlBase = ""
local productPageUrlPath = ""
local numericId = ""
local inventoryItemId = ""
local discountType = ""
local discountValue = 0
local sku = ""
local weight = 0
local j = 0
local count_j = 0
local text = ""
local strVal = ""
local metadataItems = jResp:int_of("metadata.items")
local metadataOffset = jResp:int_of("metadata.offset")
local totalResults = jResp:int_of("totalResults")
local i = 0
local count_i = jResp:size_of_array("products")
while i < count_i do
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")
stockInStock = jResp:bool_of("products[i].stock.inStock")
priceCurrency = jResp:string_of("products[i].price.currency")
pricePrice = jResp:int_of("products[i].price.price")
priceDiscountedPrice = jResp:int_of("products[i].price.discountedPrice")
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")
priceDataDiscountedPrice = jResp:int_of("products[i].priceData.discountedPrice")
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")
sku = jResp:string_of("products[i].sku")
weight = jResp:int_of("products[i].weight")
j = 0
count_j = jResp:size_of_array("products[i].additionalInfoSections")
while j < count_j do
jResp.j = j
j = j + 1
end
j = 0
count_j = jResp:size_of_array("products[i].ribbons")
while j < count_j do
jResp.j = j
text = jResp:string_of("products[i].ribbons[j].text")
j = j + 1
end
j = 0
count_j = jResp:size_of_array("products[i].media.items")
while j < count_j do
jResp.j = j
j = j + 1
end
j = 0
count_j = jResp:size_of_array("products[i].customTextFields")
while j < count_j do
jResp.j = j
j = j + 1
end
j = 0
count_j = jResp:size_of_array("products[i].productOptions")
while j < count_j do
jResp.j = j
j = j + 1
end
j = 0
count_j = jResp:size_of_array("products[i].collectionIds")
while j < count_j do
jResp.j = j
strVal = jResp:string_of("products[i].collectionIds[j]")
j = j + 1
end
j = 0
count_j = jResp:size_of_array("products[i].variants")
while j < count_j do
jResp.j = j
j = j + 1
end
i = i + 1
end