Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(SQL Server) Shopify Get all products that belong to a certain collectionGet all products that belong to a certain collection
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls. -- CREATE PROCEDURE ChilkatSample AS BEGIN DECLARE @hr int DECLARE @iTmp0 int -- Important: Do not use nvarchar(max). See the warning about using nvarchar(max). DECLARE @sTmp0 nvarchar(4000) DECLARE @rest int -- Use "Chilkat_9_5_0.Rest" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.Rest', @rest OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END DECLARE @success int EXEC sp_OAMethod @rest, 'SetAuthBasic', @success OUT, 'SHOPIFY_PRIVATE_API_KEY', 'SHOPIFY_PRIVATE_API_KEY' EXEC sp_OAMethod @rest, 'Connect', @success OUT, 'chilkat.myshopify.com', 443, 1, 1 IF @success <> 1 BEGIN EXEC sp_OAGetProperty @rest, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @rest RETURN END DECLARE @sbJson int -- Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbJson OUT EXEC sp_OAMethod @rest, 'FullRequestNoBodySb', @success OUT, 'GET', '/admin/products.json?collection_id=841564295', @sbJson IF @success <> 1 BEGIN EXEC sp_OAGetProperty @rest, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @rest EXEC @hr = sp_OADestroy @sbJson RETURN END EXEC sp_OAGetProperty @rest, 'ResponseStatusCode', @iTmp0 OUT IF @iTmp0 <> 200 BEGIN EXEC sp_OAGetProperty @rest, 'ResponseStatusCode', @iTmp0 OUT PRINT 'Received error response code: ' + @iTmp0 PRINT 'Response body:' EXEC sp_OAMethod @sbJson, 'GetAsString', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @rest EXEC @hr = sp_OADestroy @sbJson RETURN END DECLARE @json int -- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT EXEC sp_OAMethod @json, 'LoadSb', @success OUT, @sbJson -- The following code parses the JSON response. -- A sample JSON response is shown below the sample code. DECLARE @i int DECLARE @count_i int DECLARE @id int DECLARE @title nvarchar(4000) DECLARE @body_html nvarchar(4000) DECLARE @vendor nvarchar(4000) DECLARE @product_type nvarchar(4000) DECLARE @created_at nvarchar(4000) DECLARE @handle nvarchar(4000) DECLARE @updated_at nvarchar(4000) DECLARE @published_at nvarchar(4000) DECLARE @template_suffix int DECLARE @published_scope nvarchar(4000) DECLARE @tags nvarchar(4000) DECLARE @imageId int DECLARE @imageProduct_id int DECLARE @imagePosition int DECLARE @imageCreated_at nvarchar(4000) DECLARE @imageUpdated_at nvarchar(4000) DECLARE @imageWidth int DECLARE @imageHeight int DECLARE @imageSrc nvarchar(4000) DECLARE @j int DECLARE @count_j int DECLARE @product_id int DECLARE @price nvarchar(4000) DECLARE @sku nvarchar(4000) DECLARE @position int DECLARE @grams int DECLARE @inventory_policy nvarchar(4000) DECLARE @compare_at_price int DECLARE @fulfillment_service nvarchar(4000) DECLARE @inventory_management nvarchar(4000) DECLARE @option1 nvarchar(4000) DECLARE @option2 int DECLARE @option3 int DECLARE @taxable int DECLARE @barcode nvarchar(4000) DECLARE @image_id int DECLARE @inventory_quantity int DECLARE @weight int DECLARE @weight_unit nvarchar(4000) DECLARE @old_inventory_quantity int DECLARE @requires_shipping int DECLARE @name nvarchar(4000) DECLARE @k int DECLARE @count_k int DECLARE @strVal nvarchar(4000) DECLARE @width int DECLARE @height int DECLARE @src nvarchar(4000) DECLARE @intVal int SELECT @i = 0 EXEC sp_OAMethod @json, 'SizeOfArray', @count_i OUT, 'products' WHILE @i < @count_i BEGIN EXEC sp_OASetProperty @json, 'I', @i EXEC sp_OAMethod @json, 'IntOf', @id OUT, 'products[i].id' EXEC sp_OAMethod @json, 'StringOf', @title OUT, 'products[i].title' EXEC sp_OAMethod @json, 'StringOf', @body_html OUT, 'products[i].body_html' EXEC sp_OAMethod @json, 'StringOf', @vendor OUT, 'products[i].vendor' EXEC sp_OAMethod @json, 'StringOf', @product_type OUT, 'products[i].product_type' EXEC sp_OAMethod @json, 'StringOf', @created_at OUT, 'products[i].created_at' EXEC sp_OAMethod @json, 'StringOf', @handle OUT, 'products[i].handle' EXEC sp_OAMethod @json, 'StringOf', @updated_at OUT, 'products[i].updated_at' EXEC sp_OAMethod @json, 'StringOf', @published_at OUT, 'products[i].published_at' EXEC sp_OAMethod @json, 'IsNullOf', @template_suffix OUT, 'products[i].template_suffix' EXEC sp_OAMethod @json, 'StringOf', @published_scope OUT, 'products[i].published_scope' EXEC sp_OAMethod @json, 'StringOf', @tags OUT, 'products[i].tags' EXEC sp_OAMethod @json, 'IntOf', @imageId OUT, 'products[i].image.id' EXEC sp_OAMethod @json, 'IntOf', @imageProduct_id OUT, 'products[i].image.product_id' EXEC sp_OAMethod @json, 'IntOf', @imagePosition OUT, 'products[i].image.position' EXEC sp_OAMethod @json, 'StringOf', @imageCreated_at OUT, 'products[i].image.created_at' EXEC sp_OAMethod @json, 'StringOf', @imageUpdated_at OUT, 'products[i].image.updated_at' EXEC sp_OAMethod @json, 'IntOf', @imageWidth OUT, 'products[i].image.width' EXEC sp_OAMethod @json, 'IntOf', @imageHeight OUT, 'products[i].image.height' EXEC sp_OAMethod @json, 'StringOf', @imageSrc OUT, 'products[i].image.src' SELECT @j = 0 EXEC sp_OAMethod @json, 'SizeOfArray', @count_j OUT, 'products[i].variants' WHILE @j < @count_j BEGIN EXEC sp_OASetProperty @json, 'J', @j EXEC sp_OAMethod @json, 'IntOf', @id OUT, 'products[i].variants[j].id' EXEC sp_OAMethod @json, 'IntOf', @product_id OUT, 'products[i].variants[j].product_id' EXEC sp_OAMethod @json, 'StringOf', @title OUT, 'products[i].variants[j].title' EXEC sp_OAMethod @json, 'StringOf', @price OUT, 'products[i].variants[j].price' EXEC sp_OAMethod @json, 'StringOf', @sku OUT, 'products[i].variants[j].sku' EXEC sp_OAMethod @json, 'IntOf', @position OUT, 'products[i].variants[j].position' EXEC sp_OAMethod @json, 'IntOf', @grams OUT, 'products[i].variants[j].grams' EXEC sp_OAMethod @json, 'StringOf', @inventory_policy OUT, 'products[i].variants[j].inventory_policy' EXEC sp_OAMethod @json, 'IsNullOf', @compare_at_price OUT, 'products[i].variants[j].compare_at_price' EXEC sp_OAMethod @json, 'StringOf', @fulfillment_service OUT, 'products[i].variants[j].fulfillment_service' EXEC sp_OAMethod @json, 'StringOf', @inventory_management OUT, 'products[i].variants[j].inventory_management' EXEC sp_OAMethod @json, 'StringOf', @option1 OUT, 'products[i].variants[j].option1' EXEC sp_OAMethod @json, 'IsNullOf', @option2 OUT, 'products[i].variants[j].option2' EXEC sp_OAMethod @json, 'IsNullOf', @option3 OUT, 'products[i].variants[j].option3' EXEC sp_OAMethod @json, 'StringOf', @created_at OUT, 'products[i].variants[j].created_at' EXEC sp_OAMethod @json, 'StringOf', @updated_at OUT, 'products[i].variants[j].updated_at' EXEC sp_OAMethod @json, 'BoolOf', @taxable OUT, 'products[i].variants[j].taxable' EXEC sp_OAMethod @json, 'StringOf', @barcode OUT, 'products[i].variants[j].barcode' EXEC sp_OAMethod @json, 'IntOf', @image_id OUT, 'products[i].variants[j].image_id' EXEC sp_OAMethod @json, 'IntOf', @inventory_quantity OUT, 'products[i].variants[j].inventory_quantity' EXEC sp_OAMethod @json, 'IntOf', @weight OUT, 'products[i].variants[j].weight' EXEC sp_OAMethod @json, 'StringOf', @weight_unit OUT, 'products[i].variants[j].weight_unit' EXEC sp_OAMethod @json, 'IntOf', @old_inventory_quantity OUT, 'products[i].variants[j].old_inventory_quantity' EXEC sp_OAMethod @json, 'BoolOf', @requires_shipping OUT, 'products[i].variants[j].requires_shipping' SELECT @j = @j + 1 END SELECT @j = 0 EXEC sp_OAMethod @json, 'SizeOfArray', @count_j OUT, 'products[i].options' WHILE @j < @count_j BEGIN EXEC sp_OASetProperty @json, 'J', @j EXEC sp_OAMethod @json, 'IntOf', @id OUT, 'products[i].options[j].id' EXEC sp_OAMethod @json, 'IntOf', @product_id OUT, 'products[i].options[j].product_id' EXEC sp_OAMethod @json, 'StringOf', @name OUT, 'products[i].options[j].name' EXEC sp_OAMethod @json, 'IntOf', @position OUT, 'products[i].options[j].position' SELECT @k = 0 EXEC sp_OAMethod @json, 'SizeOfArray', @count_k OUT, 'products[i].options[j].values' WHILE @k < @count_k BEGIN EXEC sp_OASetProperty @json, 'K', @k EXEC sp_OAMethod @json, 'StringOf', @strVal OUT, 'products[i].options[j].values[k]' SELECT @k = @k + 1 END SELECT @j = @j + 1 END SELECT @j = 0 EXEC sp_OAMethod @json, 'SizeOfArray', @count_j OUT, 'products[i].images' WHILE @j < @count_j BEGIN EXEC sp_OASetProperty @json, 'J', @j EXEC sp_OAMethod @json, 'IntOf', @id OUT, 'products[i].images[j].id' EXEC sp_OAMethod @json, 'IntOf', @product_id OUT, 'products[i].images[j].product_id' EXEC sp_OAMethod @json, 'IntOf', @position OUT, 'products[i].images[j].position' EXEC sp_OAMethod @json, 'StringOf', @created_at OUT, 'products[i].images[j].created_at' EXEC sp_OAMethod @json, 'StringOf', @updated_at OUT, 'products[i].images[j].updated_at' EXEC sp_OAMethod @json, 'IntOf', @width OUT, 'products[i].images[j].width' EXEC sp_OAMethod @json, 'IntOf', @height OUT, 'products[i].images[j].height' EXEC sp_OAMethod @json, 'StringOf', @src OUT, 'products[i].images[j].src' SELECT @k = 0 EXEC sp_OAMethod @json, 'SizeOfArray', @count_k OUT, 'products[i].images[j].variant_ids' WHILE @k < @count_k BEGIN EXEC sp_OASetProperty @json, 'K', @k EXEC sp_OAMethod @json, 'IntOf', @intVal OUT, 'products[i].images[j].variant_ids[k]' SELECT @k = @k + 1 END SELECT @j = @j + 1 END SELECT @j = 0 EXEC sp_OAMethod @json, 'SizeOfArray', @count_j OUT, 'products[i].image.variant_ids' WHILE @j < @count_j BEGIN EXEC sp_OASetProperty @json, 'J', @j SELECT @j = @j + 1 END SELECT @i = @i + 1 END -- A sample JSON response body that is parsed by the above code: -- { -- "products": [ -- { -- "id": 632910392, -- "title": "IPod Nano - 8GB", -- "body_html": "<p>It's the small iPod with one very big idea: Video. Now the world's most popular music player, available in 4GB and 8GB models, lets you enjoy TV shows, movies, video podcasts, and more. The larger, brighter display means amazing picture quality. In six eye-catching colors, iPod nano is stunning all around. And with models starting at just $149, little speaks volumes.<\/p>", -- "vendor": "Apple", -- "product_type": "Cult Products", -- "created_at": "2017-09-22T14:08:02-04:00", -- "handle": "ipod-nano", -- "updated_at": "2017-09-22T14:08:02-04:00", -- "published_at": "2007-12-31T19:00:00-05:00", -- "template_suffix": null, -- "published_scope": "web", -- "tags": "Emotive, Flash Memory, MP3, Music", -- "variants": [ -- { -- "id": 808950810, -- "product_id": 632910392, -- "title": "Pink", -- "price": "199.00", -- "sku": "IPOD2008PINK", -- "position": 1, -- "grams": 567, -- "inventory_policy": "continue", -- "compare_at_price": null, -- "fulfillment_service": "manual", -- "inventory_management": "shopify", -- "option1": "Pink", -- "option2": null, -- "option3": null, -- "created_at": "2017-09-22T14:08:02-04:00", -- "updated_at": "2017-09-22T14:08:02-04:00", -- "taxable": true, -- "barcode": "1234_pink", -- "image_id": 562641783, -- "inventory_quantity": 10, -- "weight": 1.25, -- "weight_unit": "lb", -- "old_inventory_quantity": 10, -- "requires_shipping": true -- }, -- { -- "id": 49148385, -- "product_id": 632910392, -- "title": "Red", -- "price": "199.00", -- "sku": "IPOD2008RED", -- "position": 2, -- "grams": 567, -- "inventory_policy": "continue", -- "compare_at_price": null, -- "fulfillment_service": "manual", -- "inventory_management": "shopify", -- "option1": "Red", -- "option2": null, -- "option3": null, -- "created_at": "2017-09-22T14:08:02-04:00", -- "updated_at": "2017-09-22T14:08:02-04:00", -- "taxable": true, -- "barcode": "1234_red", -- "image_id": null, -- "inventory_quantity": 20, -- "weight": 1.25, -- "weight_unit": "lb", -- "old_inventory_quantity": 20, -- "requires_shipping": true -- }, -- { -- "id": 39072856, -- "product_id": 632910392, -- "title": "Green", -- "price": "199.00", -- "sku": "IPOD2008GREEN", -- "position": 3, -- "grams": 567, -- "inventory_policy": "continue", -- "compare_at_price": null, -- "fulfillment_service": "manual", -- "inventory_management": "shopify", -- "option1": "Green", -- "option2": null, -- "option3": null, -- "created_at": "2017-09-22T14:08:02-04:00", -- "updated_at": "2017-09-22T14:08:02-04:00", -- "taxable": true, -- "barcode": "1234_green", -- "image_id": null, -- "inventory_quantity": 30, -- "weight": 1.25, -- "weight_unit": "lb", -- "old_inventory_quantity": 30, -- "requires_shipping": true -- }, -- { -- "id": 457924702, -- "product_id": 632910392, -- "title": "Black", -- "price": "199.00", -- "sku": "IPOD2008BLACK", -- "position": 4, -- "grams": 567, -- "inventory_policy": "continue", -- "compare_at_price": null, -- "fulfillment_service": "manual", -- "inventory_management": "shopify", -- "option1": "Black", -- "option2": null, -- "option3": null, -- "created_at": "2017-09-22T14:08:02-04:00", -- "updated_at": "2017-09-22T14:08:02-04:00", -- "taxable": true, -- "barcode": "1234_black", -- "image_id": null, -- "inventory_quantity": 40, -- "weight": 1.25, -- "weight_unit": "lb", -- "old_inventory_quantity": 40, -- "requires_shipping": true -- } -- ], -- "options": [ -- { -- "id": 594680422, -- "product_id": 632910392, -- "name": "Color", -- "position": 1, -- "values": [ -- "Pink", -- "Red", -- "Green", -- "Black" -- ] -- } -- ], -- "images": [ -- { -- "id": 850703190, -- "product_id": 632910392, -- "position": 1, -- "created_at": "2017-09-22T14:08:02-04:00", -- "updated_at": "2017-09-22T14:08:02-04:00", -- "width": 123, -- "height": 456, -- "src": "https:\/\/cdn.shopify.com\/s\/files\/1\/0006\/9093\/3842\/products\/ipod-nano.png?v=1506103682", -- "variant_ids": [ -- ] -- }, -- { -- "id": 562641783, -- "product_id": 632910392, -- "position": 2, -- "created_at": "2017-09-22T14:08:02-04:00", -- "updated_at": "2017-09-22T14:08:02-04:00", -- "width": 123, -- "height": 456, -- "src": "https:\/\/cdn.shopify.com\/s\/files\/1\/0006\/9093\/3842\/products\/ipod-nano-2.png?v=1506103682", -- "variant_ids": [ -- 808950810 -- ] -- } -- ], -- "image": { -- "id": 850703190, -- "product_id": 632910392, -- "position": 1, -- "created_at": "2017-09-22T14:08:02-04:00", -- "updated_at": "2017-09-22T14:08:02-04:00", -- "width": 123, -- "height": 456, -- "src": "https:\/\/cdn.shopify.com\/s\/files\/1\/0006\/9093\/3842\/products\/ipod-nano.png?v=1506103682", -- "variant_ids": [ -- ] -- } -- } -- ] -- } PRINT 'Example Completed.' EXEC @hr = sp_OADestroy @rest EXEC @hr = sp_OADestroy @sbJson EXEC @hr = sp_OADestroy @json END GO |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.