SQL Server
SQL Server
WiX - Get all Products in a Store
See more WiX Examples
Gets the first page of products in a store.Chilkat SQL Server Downloads
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
-- Important: Do not use nvarchar(max). See the warning about using nvarchar(max).
DECLARE @sTmp0 nvarchar(4000)
DECLARE @success int
SELECT @success = 0
-- This example assumes the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
DECLARE @http int
EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
-- Implements the following CURL command:
-- curl -X POST -H "Content-Type: application/json" \
-- -d '{
-- "includeVariants": true
-- }' https://www.wixapis.com/stores/v1/products/query
DECLARE @json int
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT
EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'includeVariants', 1
EXEC sp_OASetProperty @http, 'AuthToken', 'ACCESS_TOKEN'
DECLARE @resp int
EXEC @hr = sp_OACreate 'Chilkat.HttpResponse', @resp OUT
EXEC sp_OAMethod @http, 'HttpJson', @success OUT, 'POST', 'https://www.wixapis.com/stores/v1/products/query', @json, 'application/json', @resp
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @json
EXEC @hr = sp_OADestroy @resp
RETURN
END
DECLARE @sbResponseBody int
EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbResponseBody OUT
EXEC sp_OAMethod @resp, 'GetBodySb', @success OUT, @sbResponseBody
DECLARE @jResp int
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @jResp OUT
EXEC sp_OAMethod @jResp, 'LoadSb', @success OUT, @sbResponseBody
EXEC sp_OASetProperty @jResp, 'EmitCompact', 0
PRINT 'Response Body:'
EXEC sp_OAMethod @jResp, 'Emit', @sTmp0 OUT
PRINT @sTmp0
DECLARE @respStatusCode int
EXEC sp_OAGetProperty @resp, 'StatusCode', @respStatusCode OUT
PRINT 'Response Status Code = ' + @respStatusCode
IF @respStatusCode >= 400
BEGIN
PRINT 'Response Header:'
EXEC sp_OAGetProperty @resp, 'Header', @sTmp0 OUT
PRINT @sTmp0
PRINT 'Failed.'
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @json
EXEC @hr = sp_OADestroy @resp
EXEC @hr = sp_OADestroy @sbResponseBody
EXEC @hr = sp_OADestroy @jResp
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
DECLARE @id nvarchar(4000)
DECLARE @name nvarchar(4000)
DECLARE @slug nvarchar(4000)
DECLARE @visible int
DECLARE @productType nvarchar(4000)
DECLARE @description nvarchar(4000)
DECLARE @stockTrackInventory int
DECLARE @stockQuantity int
DECLARE @stockInStock int
DECLARE @priceCurrency nvarchar(4000)
DECLARE @pricePrice int
DECLARE @priceDiscountedPrice int
DECLARE @priceFormattedPrice nvarchar(4000)
DECLARE @priceFormattedDiscountedPrice nvarchar(4000)
DECLARE @priceDataCurrency nvarchar(4000)
DECLARE @priceDataPrice int
DECLARE @priceDataDiscountedPrice int
DECLARE @priceDataFormattedPrice nvarchar(4000)
DECLARE @priceDataFormattedDiscountedPrice nvarchar(4000)
DECLARE @manageVariants int
DECLARE @productPageUrlBase nvarchar(4000)
DECLARE @productPageUrlPath nvarchar(4000)
DECLARE @numericId nvarchar(4000)
DECLARE @inventoryItemId nvarchar(4000)
DECLARE @discountType nvarchar(4000)
DECLARE @discountValue int
DECLARE @sku nvarchar(4000)
DECLARE @weight int
DECLARE @j int
DECLARE @count_j int
DECLARE @text nvarchar(4000)
DECLARE @strVal nvarchar(4000)
DECLARE @metadataItems int
EXEC sp_OAMethod @jResp, 'IntOf', @metadataItems OUT, 'metadata.items'
DECLARE @metadataOffset int
EXEC sp_OAMethod @jResp, 'IntOf', @metadataOffset OUT, 'metadata.offset'
DECLARE @totalResults int
EXEC sp_OAMethod @jResp, 'IntOf', @totalResults OUT, 'totalResults'
DECLARE @i int
SELECT @i = 0
DECLARE @count_i int
EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'products'
WHILE @i < @count_i
BEGIN
EXEC sp_OASetProperty @jResp, 'I', @i
EXEC sp_OAMethod @jResp, 'StringOf', @id OUT, 'products[i].id'
EXEC sp_OAMethod @jResp, 'StringOf', @name OUT, 'products[i].name'
EXEC sp_OAMethod @jResp, 'StringOf', @slug OUT, 'products[i].slug'
EXEC sp_OAMethod @jResp, 'BoolOf', @visible OUT, 'products[i].visible'
EXEC sp_OAMethod @jResp, 'StringOf', @productType OUT, 'products[i].productType'
EXEC sp_OAMethod @jResp, 'StringOf', @description OUT, 'products[i].description'
EXEC sp_OAMethod @jResp, 'BoolOf', @stockTrackInventory OUT, 'products[i].stock.trackInventory'
EXEC sp_OAMethod @jResp, 'IntOf', @stockQuantity OUT, 'products[i].stock.quantity'
EXEC sp_OAMethod @jResp, 'BoolOf', @stockInStock OUT, 'products[i].stock.inStock'
EXEC sp_OAMethod @jResp, 'StringOf', @priceCurrency OUT, 'products[i].price.currency'
EXEC sp_OAMethod @jResp, 'IntOf', @pricePrice OUT, 'products[i].price.price'
EXEC sp_OAMethod @jResp, 'IntOf', @priceDiscountedPrice OUT, 'products[i].price.discountedPrice'
EXEC sp_OAMethod @jResp, 'StringOf', @priceFormattedPrice OUT, 'products[i].price.formatted.price'
EXEC sp_OAMethod @jResp, 'StringOf', @priceFormattedDiscountedPrice OUT, 'products[i].price.formatted.discountedPrice'
EXEC sp_OAMethod @jResp, 'StringOf', @priceDataCurrency OUT, 'products[i].priceData.currency'
EXEC sp_OAMethod @jResp, 'IntOf', @priceDataPrice OUT, 'products[i].priceData.price'
EXEC sp_OAMethod @jResp, 'IntOf', @priceDataDiscountedPrice OUT, 'products[i].priceData.discountedPrice'
EXEC sp_OAMethod @jResp, 'StringOf', @priceDataFormattedPrice OUT, 'products[i].priceData.formatted.price'
EXEC sp_OAMethod @jResp, 'StringOf', @priceDataFormattedDiscountedPrice OUT, 'products[i].priceData.formatted.discountedPrice'
EXEC sp_OAMethod @jResp, 'BoolOf', @manageVariants OUT, 'products[i].manageVariants'
EXEC sp_OAMethod @jResp, 'StringOf', @productPageUrlBase OUT, 'products[i].productPageUrl.base'
EXEC sp_OAMethod @jResp, 'StringOf', @productPageUrlPath OUT, 'products[i].productPageUrl.path'
EXEC sp_OAMethod @jResp, 'StringOf', @numericId OUT, 'products[i].numericId'
EXEC sp_OAMethod @jResp, 'StringOf', @inventoryItemId OUT, 'products[i].inventoryItemId'
EXEC sp_OAMethod @jResp, 'StringOf', @discountType OUT, 'products[i].discount.type'
EXEC sp_OAMethod @jResp, 'IntOf', @discountValue OUT, 'products[i].discount.value'
EXEC sp_OAMethod @jResp, 'StringOf', @sku OUT, 'products[i].sku'
EXEC sp_OAMethod @jResp, 'IntOf', @weight OUT, 'products[i].weight'
SELECT @j = 0
EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_j OUT, 'products[i].additionalInfoSections'
WHILE @j < @count_j
BEGIN
EXEC sp_OASetProperty @jResp, 'J', @j
SELECT @j = @j + 1
END
SELECT @j = 0
EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_j OUT, 'products[i].ribbons'
WHILE @j < @count_j
BEGIN
EXEC sp_OASetProperty @jResp, 'J', @j
EXEC sp_OAMethod @jResp, 'StringOf', @text OUT, 'products[i].ribbons[j].text'
SELECT @j = @j + 1
END
SELECT @j = 0
EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_j OUT, 'products[i].media.items'
WHILE @j < @count_j
BEGIN
EXEC sp_OASetProperty @jResp, 'J', @j
SELECT @j = @j + 1
END
SELECT @j = 0
EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_j OUT, 'products[i].customTextFields'
WHILE @j < @count_j
BEGIN
EXEC sp_OASetProperty @jResp, 'J', @j
SELECT @j = @j + 1
END
SELECT @j = 0
EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_j OUT, 'products[i].productOptions'
WHILE @j < @count_j
BEGIN
EXEC sp_OASetProperty @jResp, 'J', @j
SELECT @j = @j + 1
END
SELECT @j = 0
EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_j OUT, 'products[i].collectionIds'
WHILE @j < @count_j
BEGIN
EXEC sp_OASetProperty @jResp, 'J', @j
EXEC sp_OAMethod @jResp, 'StringOf', @strVal OUT, 'products[i].collectionIds[j]'
SELECT @j = @j + 1
END
SELECT @j = 0
EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_j OUT, 'products[i].variants'
WHILE @j < @count_j
BEGIN
EXEC sp_OASetProperty @jResp, 'J', @j
SELECT @j = @j + 1
END
SELECT @i = @i + 1
END
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @json
EXEC @hr = sp_OADestroy @resp
EXEC @hr = sp_OADestroy @sbResponseBody
EXEC @hr = sp_OADestroy @jResp
END
GO