Sample code for 30+ languages & platforms
SQL Server

Shopware List Media

See more Shopware Examples

Demonstrates how to get a list of media in Shopware.

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
    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/media?limit=10', @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": 6708,
    --        "albumId": -9,
    --        "name": "sonnenblume",
    --        "description": "",
    --        "path": "https:\/\/my-shopware-shop.com\/media\/pdf\/2f\/26\/52\/sonnenblume.zip",
    --        "type": "ARCHIVE",
    --        "extension": "zip",
    --        "userId": 5,
    --        "created": "2021-03-01T00:00:00+0100",
    --        "fileSize": 216905,
    --        "width": null,
    --        "height": null,
    --        "attribute": null
    --      },
    --      {
    --        "id": 6709,
    --        "albumId": -9,
    --        "name": "csinventur_anleitung",
    --        "description": "",
    --        "path": "https:\/\/my-shopware-shop.com\/media\/pdf\/19\/21\/86\/csinventur_anleitung.pdf",
    --        "type": "PDF",
    --        "extension": "pdf",
    --        "userId": 5,
    --        "created": "2021-03-01T00:00:00+0100",
    --        "fileSize": 837131,
    --        "width": null,
    --        "height": null,
    --        "attribute": null
    --      },
    --      {
    --        "id": 6710,
    --        "albumId": -9,
    --        "name": "photos_fre_carousel_elevatorpitch_620x252",
    --        "description": "",
    --        "path": "https:\/\/my-shopware-shop.com\/media\/pdf\/d8\/d7\/b4\/photos_fre_carousel_elevatorpitch_620x252.mp4",
    --        "type": "VIDEO",
    --        "extension": "mp4",
    --        "userId": 5,
    --        "created": "2021-03-01T00:00:00+0100",
    --        "fileSize": 2499157,
    --        "width": null,
    --        "height": null,
    --        "attribute": null
    --      },
    --  
    --  	...
    --    ],
    --    "total": 31,
    --    "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 @albumId int

    DECLARE @name nvarchar(4000)

    DECLARE @description nvarchar(4000)

    DECLARE @path nvarchar(4000)

    DECLARE @v_type nvarchar(4000)

    DECLARE @extension nvarchar(4000)

    DECLARE @userId int

    DECLARE @created nvarchar(4000)

    DECLARE @fileSize int

    DECLARE @width nvarchar(4000)

    DECLARE @height nvarchar(4000)

    DECLARE @attribute 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, 'IntOf', @albumId OUT, 'data[i].albumId'
        EXEC sp_OAMethod @jResp, 'StringOf', @name OUT, 'data[i].name'
        EXEC sp_OAMethod @jResp, 'StringOf', @description OUT, 'data[i].description'
        EXEC sp_OAMethod @jResp, 'StringOf', @path OUT, 'data[i].path'
        EXEC sp_OAMethod @jResp, 'StringOf', @v_type OUT, 'data[i].type'
        EXEC sp_OAMethod @jResp, 'StringOf', @extension OUT, 'data[i].extension'
        EXEC sp_OAMethod @jResp, 'IntOf', @userId OUT, 'data[i].userId'
        EXEC sp_OAMethod @jResp, 'StringOf', @created OUT, 'data[i].created'
        EXEC sp_OAMethod @jResp, 'IntOf', @fileSize OUT, 'data[i].fileSize'
        EXEC sp_OAMethod @jResp, 'StringOf', @width OUT, 'data[i].width'
        EXEC sp_OAMethod @jResp, 'StringOf', @height OUT, 'data[i].height'
        EXEC sp_OAMethod @jResp, 'StringOf', @attribute OUT, 'data[i].attribute'
        SELECT @i = @i + 1
      END

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


END
GO