Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3/4TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

SQL Server Web API Examples

Primary Categories

AWS Translate
Azure Maps
Azure OAuth2
Azure Storage Accounts
CardConnect
Cloudfare
Facebook
GeoOp
Jira
Magento
Microsoft Calendar
Microsoft Group
Microsoft Tasks and Plans

PayPal
Peoplevox
Populi
QuickBooks
SOAP finkok.com
Shopify
Stripe
SugarCRM
Trello
Twitter
VoiceBase
Walmart
Xero
eBay
effectconnect

 

 

 

(SQL Server) Shopify Create a new unpublished product

Create a new unpublished product

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    DECLARE @sTmp0 nvarchar(4000)
    DECLARE @rest int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.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

    -- The following code creates the JSON request body.
    -- The JSON created by this code is shown below.
    DECLARE @jsonReq int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @jsonReq OUT

    EXEC sp_OAMethod @jsonReq, 'UpdateString', @success OUT, 'product.title', 'Burton Custom Freestyle 151'
    EXEC sp_OAMethod @jsonReq, 'UpdateString', @success OUT, 'product.body_html', '<strong>Good snowboard!</strong>'
    EXEC sp_OAMethod @jsonReq, 'UpdateString', @success OUT, 'product.vendor', 'Burton'
    EXEC sp_OAMethod @jsonReq, 'UpdateString', @success OUT, 'product.product_type', 'Snowboard'
    EXEC sp_OAMethod @jsonReq, 'UpdateBool', @success OUT, 'product.published', 0

    -- The JSON request body created by the above code:

    -- {
    --   "product": {
    --     "title": "Burton Custom Freestyle 151",
    --     "body_html": "<strong>Good snowboard!<\/strong>",
    --     "vendor": "Burton",
    --     "product_type": "Snowboard",
    --     "published": false
    --   }
    -- }

    DECLARE @sbReq int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.StringBuilder', @sbReq OUT

    EXEC sp_OAMethod @jsonReq, 'EmitSb', @success OUT, @sbReq

    EXEC sp_OAMethod @rest, 'AddHeader', @success OUT, 'Content-Type', 'application/json'

    DECLARE @sbJson int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.StringBuilder', @sbJson OUT

    EXEC sp_OAMethod @rest, 'FullRequestSb', @success OUT, 'POST', '/admin/products.json ', @sbReq, @sbJson
    IF @success <> 1
      BEGIN
        EXEC sp_OAGetProperty @rest, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @jsonReq
        EXEC @hr = sp_OADestroy @sbReq
        EXEC @hr = sp_OADestroy @sbJson
        RETURN
      END

    EXEC sp_OAGetProperty @rest, 'ResponseStatusCode', @iTmp0 OUT
    IF @iTmp0 <> 201
      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 @jsonReq
        EXEC @hr = sp_OADestroy @sbReq
        EXEC @hr = sp_OADestroy @sbJson
        RETURN
      END

    DECLARE @json int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.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 @productId int

    DECLARE @productTitle nvarchar(4000)

    DECLARE @productBody_html nvarchar(4000)

    DECLARE @productVendor nvarchar(4000)

    DECLARE @productProduct_type nvarchar(4000)

    DECLARE @productCreated_at nvarchar(4000)

    DECLARE @productHandle nvarchar(4000)

    DECLARE @productUpdated_at nvarchar(4000)

    DECLARE @productPublished_at int

    DECLARE @productTemplate_suffix int

    DECLARE @productPublished_scope nvarchar(4000)

    DECLARE @productTags nvarchar(4000)

    DECLARE @productImage int

    DECLARE @i int

    DECLARE @count_i int

    DECLARE @id int

    DECLARE @product_id int

    DECLARE @title nvarchar(4000)

    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 int

    DECLARE @option1 nvarchar(4000)

    DECLARE @option2 int

    DECLARE @option3 int

    DECLARE @created_at nvarchar(4000)

    DECLARE @updated_at nvarchar(4000)

    DECLARE @taxable int

    DECLARE @barcode int

    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 @j int

    DECLARE @count_j int

    DECLARE @strVal nvarchar(4000)

    EXEC sp_OAMethod @json, 'IntOf', @productId OUT, 'product.id'
    EXEC sp_OAMethod @json, 'StringOf', @productTitle OUT, 'product.title'
    EXEC sp_OAMethod @json, 'StringOf', @productBody_html OUT, 'product.body_html'
    EXEC sp_OAMethod @json, 'StringOf', @productVendor OUT, 'product.vendor'
    EXEC sp_OAMethod @json, 'StringOf', @productProduct_type OUT, 'product.product_type'
    EXEC sp_OAMethod @json, 'StringOf', @productCreated_at OUT, 'product.created_at'
    EXEC sp_OAMethod @json, 'StringOf', @productHandle OUT, 'product.handle'
    EXEC sp_OAMethod @json, 'StringOf', @productUpdated_at OUT, 'product.updated_at'
    EXEC sp_OAMethod @json, 'IsNullOf', @productPublished_at OUT, 'product.published_at'
    EXEC sp_OAMethod @json, 'IsNullOf', @productTemplate_suffix OUT, 'product.template_suffix'
    EXEC sp_OAMethod @json, 'StringOf', @productPublished_scope OUT, 'product.published_scope'
    EXEC sp_OAMethod @json, 'StringOf', @productTags OUT, 'product.tags'
    EXEC sp_OAMethod @json, 'IsNullOf', @productImage OUT, 'product.image'
    SELECT @i = 0
    EXEC sp_OAMethod @json, 'SizeOfArray', @count_i OUT, 'product.variants'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @json, 'I', @i
        EXEC sp_OAMethod @json, 'IntOf', @id OUT, 'product.variants[i].id'
        EXEC sp_OAMethod @json, 'IntOf', @product_id OUT, 'product.variants[i].product_id'
        EXEC sp_OAMethod @json, 'StringOf', @title OUT, 'product.variants[i].title'
        EXEC sp_OAMethod @json, 'StringOf', @price OUT, 'product.variants[i].price'
        EXEC sp_OAMethod @json, 'StringOf', @sku OUT, 'product.variants[i].sku'
        EXEC sp_OAMethod @json, 'IntOf', @position OUT, 'product.variants[i].position'
        EXEC sp_OAMethod @json, 'IntOf', @grams OUT, 'product.variants[i].grams'
        EXEC sp_OAMethod @json, 'StringOf', @inventory_policy OUT, 'product.variants[i].inventory_policy'
        EXEC sp_OAMethod @json, 'IsNullOf', @compare_at_price OUT, 'product.variants[i].compare_at_price'
        EXEC sp_OAMethod @json, 'StringOf', @fulfillment_service OUT, 'product.variants[i].fulfillment_service'
        EXEC sp_OAMethod @json, 'IsNullOf', @inventory_management OUT, 'product.variants[i].inventory_management'
        EXEC sp_OAMethod @json, 'StringOf', @option1 OUT, 'product.variants[i].option1'
        EXEC sp_OAMethod @json, 'IsNullOf', @option2 OUT, 'product.variants[i].option2'
        EXEC sp_OAMethod @json, 'IsNullOf', @option3 OUT, 'product.variants[i].option3'
        EXEC sp_OAMethod @json, 'StringOf', @created_at OUT, 'product.variants[i].created_at'
        EXEC sp_OAMethod @json, 'StringOf', @updated_at OUT, 'product.variants[i].updated_at'
        EXEC sp_OAMethod @json, 'BoolOf', @taxable OUT, 'product.variants[i].taxable'
        EXEC sp_OAMethod @json, 'IsNullOf', @barcode OUT, 'product.variants[i].barcode'
        EXEC sp_OAMethod @json, 'IsNullOf', @image_id OUT, 'product.variants[i].image_id'
        EXEC sp_OAMethod @json, 'IntOf', @inventory_quantity OUT, 'product.variants[i].inventory_quantity'
        EXEC sp_OAMethod @json, 'IntOf', @weight OUT, 'product.variants[i].weight'
        EXEC sp_OAMethod @json, 'StringOf', @weight_unit OUT, 'product.variants[i].weight_unit'
        EXEC sp_OAMethod @json, 'IntOf', @old_inventory_quantity OUT, 'product.variants[i].old_inventory_quantity'
        EXEC sp_OAMethod @json, 'BoolOf', @requires_shipping OUT, 'product.variants[i].requires_shipping'
        SELECT @i = @i + 1
      END
    SELECT @i = 0
    EXEC sp_OAMethod @json, 'SizeOfArray', @count_i OUT, 'product.options'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @json, 'I', @i
        EXEC sp_OAMethod @json, 'IntOf', @id OUT, 'product.options[i].id'
        EXEC sp_OAMethod @json, 'IntOf', @product_id OUT, 'product.options[i].product_id'
        EXEC sp_OAMethod @json, 'StringOf', @name OUT, 'product.options[i].name'
        EXEC sp_OAMethod @json, 'IntOf', @position OUT, 'product.options[i].position'
        SELECT @j = 0
        EXEC sp_OAMethod @json, 'SizeOfArray', @count_j OUT, 'product.options[i].values'
        WHILE @j < @count_j
          BEGIN
            EXEC sp_OASetProperty @json, 'J', @j
            EXEC sp_OAMethod @json, 'StringOf', @strVal OUT, 'product.options[i].values[j]'
            SELECT @j = @j + 1
          END
        SELECT @i = @i + 1
      END
    SELECT @i = 0
    EXEC sp_OAMethod @json, 'SizeOfArray', @count_i OUT, 'product.images'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @json, 'I', @i
        SELECT @i = @i + 1
      END

    -- A sample JSON response body that is parsed by the above code:

    -- {
    --   "product": {
    --     "id": 1071559753,
    --     "title": "Burton Custom Freestyle 151",
    --     "body_html": "<strong>Good snowboard!<\/strong>",
    --     "vendor": "Burton",
    --     "product_type": "Snowboard",
    --     "created_at": "2017-09-22T14:48:52-04:00",
    --     "handle": "burton-custom-freestyle-151",
    --     "updated_at": "2017-09-22T14:48:52-04:00",
    --     "published_at": null,
    --     "template_suffix": null,
    --     "published_scope": "global",
    --     "tags": "",
    --     "variants": [
    --       {
    --         "id": 1070325224,
    --         "product_id": 1071559753,
    --         "title": "Default Title",
    --         "price": "0.00",
    --         "sku": "",
    --         "position": 1,
    --         "grams": 0,
    --         "inventory_policy": "deny",
    --         "compare_at_price": null,
    --         "fulfillment_service": "manual",
    --         "inventory_management": null,
    --         "option1": "Default Title",
    --         "option2": null,
    --         "option3": null,
    --         "created_at": "2017-09-22T14:48:52-04:00",
    --         "updated_at": "2017-09-22T14:48:52-04:00",
    --         "taxable": true,
    --         "barcode": null,
    --         "image_id": null,
    --         "inventory_quantity": 1,
    --         "weight": 0.0,
    --         "weight_unit": "lb",
    --         "old_inventory_quantity": 1,
    --         "requires_shipping": true
    --       }
    --     ],
    --     "options": [
    --       {
    --         "id": 1022828912,
    --         "product_id": 1071559753,
    --         "name": "Title",
    --         "position": 1,
    --         "values": [
    --           "Default Title"
    --         ]
    --       }
    --     ],
    --     "images": [
    --     ],
    --     "image": null
    --   }
    -- }


    PRINT 'Example Completed.'

    EXEC @hr = sp_OADestroy @rest
    EXEC @hr = sp_OADestroy @jsonReq
    EXEC @hr = sp_OADestroy @sbReq
    EXEC @hr = sp_OADestroy @sbJson
    EXEC @hr = sp_OADestroy @json


END
GO

 

© 2000-2019 Chilkat Software, Inc. All Rights Reserved.