Tcl
Tcl
WiX - Get all Products in a Store
See more WiX Examples
Gets the first page of products in a store.Chilkat Tcl Downloads
load ./chilkat.dll
set success 0
# This example assumes the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.
set http [new_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
set json [new_CkJsonObject]
CkJsonObject_UpdateBool $json "includeVariants" 1
CkHttp_put_AuthToken $http "ACCESS_TOKEN"
set resp [new_CkHttpResponse]
set success [CkHttp_HttpJson $http "POST" "https://www.wixapis.com/stores/v1/products/query" $json "application/json" $resp]
if {$success == 0} then {
puts [CkHttp_lastErrorText $http]
delete_CkHttp $http
delete_CkJsonObject $json
delete_CkHttpResponse $resp
exit
}
set sbResponseBody [new_CkStringBuilder]
CkHttpResponse_GetBodySb $resp $sbResponseBody
set jResp [new_CkJsonObject]
CkJsonObject_LoadSb $jResp $sbResponseBody
CkJsonObject_put_EmitCompact $jResp 0
puts "Response Body:"
puts [CkJsonObject_emit $jResp]
set respStatusCode [CkHttpResponse_get_StatusCode $resp]
puts "Response Status Code = $respStatusCode"
if {$respStatusCode >= 400} then {
puts "Response Header:"
puts [CkHttpResponse_header $resp]
puts "Failed."
delete_CkHttp $http
delete_CkJsonObject $json
delete_CkHttpResponse $resp
delete_CkStringBuilder $sbResponseBody
delete_CkJsonObject $jResp
exit
}
# 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
set metadataItems [CkJsonObject_IntOf $jResp "metadata.items"]
set metadataOffset [CkJsonObject_IntOf $jResp "metadata.offset"]
set totalResults [CkJsonObject_IntOf $jResp "totalResults"]
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "products"]
while {$i < $count_i} {
CkJsonObject_put_I $jResp $i
set id [CkJsonObject_stringOf $jResp "products[i].id"]
set name [CkJsonObject_stringOf $jResp "products[i].name"]
set slug [CkJsonObject_stringOf $jResp "products[i].slug"]
set visible [CkJsonObject_BoolOf $jResp "products[i].visible"]
set productType [CkJsonObject_stringOf $jResp "products[i].productType"]
set description [CkJsonObject_stringOf $jResp "products[i].description"]
set stockTrackInventory [CkJsonObject_BoolOf $jResp "products[i].stock.trackInventory"]
set stockQuantity [CkJsonObject_IntOf $jResp "products[i].stock.quantity"]
set stockInStock [CkJsonObject_BoolOf $jResp "products[i].stock.inStock"]
set priceCurrency [CkJsonObject_stringOf $jResp "products[i].price.currency"]
set pricePrice [CkJsonObject_IntOf $jResp "products[i].price.price"]
set priceDiscountedPrice [CkJsonObject_IntOf $jResp "products[i].price.discountedPrice"]
set priceFormattedPrice [CkJsonObject_stringOf $jResp "products[i].price.formatted.price"]
set priceFormattedDiscountedPrice [CkJsonObject_stringOf $jResp "products[i].price.formatted.discountedPrice"]
set priceDataCurrency [CkJsonObject_stringOf $jResp "products[i].priceData.currency"]
set priceDataPrice [CkJsonObject_IntOf $jResp "products[i].priceData.price"]
set priceDataDiscountedPrice [CkJsonObject_IntOf $jResp "products[i].priceData.discountedPrice"]
set priceDataFormattedPrice [CkJsonObject_stringOf $jResp "products[i].priceData.formatted.price"]
set priceDataFormattedDiscountedPrice [CkJsonObject_stringOf $jResp "products[i].priceData.formatted.discountedPrice"]
set manageVariants [CkJsonObject_BoolOf $jResp "products[i].manageVariants"]
set productPageUrlBase [CkJsonObject_stringOf $jResp "products[i].productPageUrl.base"]
set productPageUrlPath [CkJsonObject_stringOf $jResp "products[i].productPageUrl.path"]
set numericId [CkJsonObject_stringOf $jResp "products[i].numericId"]
set inventoryItemId [CkJsonObject_stringOf $jResp "products[i].inventoryItemId"]
set discountType [CkJsonObject_stringOf $jResp "products[i].discount.type"]
set discountValue [CkJsonObject_IntOf $jResp "products[i].discount.value"]
set sku [CkJsonObject_stringOf $jResp "products[i].sku"]
set weight [CkJsonObject_IntOf $jResp "products[i].weight"]
set j 0
set count_j [CkJsonObject_SizeOfArray $jResp "products[i].additionalInfoSections"]
while {$j < $count_j} {
CkJsonObject_put_J $jResp $j
set j [expr $j + 1]
}
set j 0
set count_j [CkJsonObject_SizeOfArray $jResp "products[i].ribbons"]
while {$j < $count_j} {
CkJsonObject_put_J $jResp $j
set text [CkJsonObject_stringOf $jResp "products[i].ribbons[j].text"]
set j [expr $j + 1]
}
set j 0
set count_j [CkJsonObject_SizeOfArray $jResp "products[i].media.items"]
while {$j < $count_j} {
CkJsonObject_put_J $jResp $j
set j [expr $j + 1]
}
set j 0
set count_j [CkJsonObject_SizeOfArray $jResp "products[i].customTextFields"]
while {$j < $count_j} {
CkJsonObject_put_J $jResp $j
set j [expr $j + 1]
}
set j 0
set count_j [CkJsonObject_SizeOfArray $jResp "products[i].productOptions"]
while {$j < $count_j} {
CkJsonObject_put_J $jResp $j
set j [expr $j + 1]
}
set j 0
set count_j [CkJsonObject_SizeOfArray $jResp "products[i].collectionIds"]
while {$j < $count_j} {
CkJsonObject_put_J $jResp $j
set strVal [CkJsonObject_stringOf $jResp "products[i].collectionIds[j]"]
set j [expr $j + 1]
}
set j 0
set count_j [CkJsonObject_SizeOfArray $jResp "products[i].variants"]
while {$j < $count_j} {
CkJsonObject_put_J $jResp $j
set j [expr $j + 1]
}
set i [expr $i + 1]
}
delete_CkHttp $http
delete_CkJsonObject $json
delete_CkHttpResponse $resp
delete_CkStringBuilder $sbResponseBody
delete_CkJsonObject $jResp