Sample code for 30+ languages & platforms
SQL Server

Shopware List Categories

See more Shopware Examples

List categories in your Shopware database.

Chilkat SQL Server Downloads

SQL Server
-- 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

    EXEC sp_OASetProperty @http, 'Login', 'api_username'
    EXEC sp_OASetProperty @http, 'Password', 'api_key'
    EXEC sp_OASetProperty @http, 'BasicAuth', 1

    DECLARE @sbResponseBody int
    EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbResponseBody OUT

    EXEC sp_OAMethod @http, 'QuickGetSb', @success OUT, 'https://my-shopware-shop.com/api/categories?limit=2', @sbResponseBody
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @sbResponseBody
        RETURN
      END

    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

    -- Sample JSON response:
    -- (Sample code for parsing the JSON response is shown below)

    -- {
    --   "data": [
    --     {
    --       "id": 1,
    --       "active": true,
    --       "name": "Root",
    --       "position": 0,
    --       "parentId": null,
    --       "mediaId": null,
    --       "childrenCount": "3",
    --       "articleCount": "0"
    --     },
    --     {
    --       "id": 384,
    --       "active": true,
    --       "name": "Deutsch",
    --       "position": 0,
    --       "parentId": 1,
    --       "mediaId": null,
    --       "childrenCount": "9",
    --       "articleCount": "32"
    --     }
    --   ],
    --   "total": 118,
    --   "success": true
    -- }

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

    DECLARE @active int

    DECLARE @name nvarchar(4000)

    DECLARE @position int

    DECLARE @parentId nvarchar(4000)

    DECLARE @mediaId nvarchar(4000)

    DECLARE @childrenCount nvarchar(4000)

    DECLARE @articleCount nvarchar(4000)

    DECLARE @total int
    EXEC sp_OAMethod @jResp, 'IntOf', @total OUT, 'total'
    EXEC sp_OAMethod @jResp, 'BoolOf', @success OUT, 'success'
    DECLARE @i int
    SELECT @i = 0
    DECLARE @count_i int
    EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'data'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @jResp, 'I', @i
        EXEC sp_OAMethod @jResp, 'IntOf', @id OUT, 'data[i].id'
        EXEC sp_OAMethod @jResp, 'BoolOf', @active OUT, 'data[i].active'
        EXEC sp_OAMethod @jResp, 'StringOf', @name OUT, 'data[i].name'
        EXEC sp_OAMethod @jResp, 'IntOf', @position OUT, 'data[i].position'
        EXEC sp_OAMethod @jResp, 'StringOf', @parentId OUT, 'data[i].parentId'
        EXEC sp_OAMethod @jResp, 'StringOf', @mediaId OUT, 'data[i].mediaId'
        EXEC sp_OAMethod @jResp, 'StringOf', @childrenCount OUT, 'data[i].childrenCount'
        EXEC sp_OAMethod @jResp, 'StringOf', @articleCount OUT, 'data[i].articleCount'
        SELECT @i = @i + 1
      END

    EXEC @hr = sp_OADestroy @http
    EXEC @hr = sp_OADestroy @sbResponseBody
    EXEC @hr = sp_OADestroy @jResp


END
GO