Sample code for 30+ languages & platforms
Tcl

Shopware List Media

See more Shopware Examples

Demonstrates how to get a list of media in Shopware.

Chilkat Tcl Downloads

Tcl

load ./chilkat.dll

set success 0

# This example assumes the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.

set http [new_CkHttp]

CkHttp_put_Login $http "api_username"
CkHttp_put_Password $http "api_key"
CkHttp_put_BasicAuth $http 1

set sbResponseBody [new_CkStringBuilder]

set success [CkHttp_QuickGetSb $http "https://my-shopware-shop.com/api/media?limit=10" $sbResponseBody]
if {$success == 0} then {
    puts [CkHttp_lastErrorText $http]
    delete_CkHttp $http
    delete_CkStringBuilder $sbResponseBody
    exit
}

set jResp [new_CkJsonObject]

CkJsonObject_LoadSb $jResp $sbResponseBody
CkJsonObject_put_EmitCompact $jResp 0

puts "Response Body:"
puts [CkJsonObject_emit $jResp]

# 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

set total [CkJsonObject_IntOf $jResp "total"]
set success [CkJsonObject_BoolOf $jResp "success"]
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "data"]
while {$i < $count_i} {
    CkJsonObject_put_I $jResp $i
    set id [CkJsonObject_IntOf $jResp "data[i].id"]
    set albumId [CkJsonObject_IntOf $jResp "data[i].albumId"]
    set name [CkJsonObject_stringOf $jResp "data[i].name"]
    set description [CkJsonObject_stringOf $jResp "data[i].description"]
    set path [CkJsonObject_stringOf $jResp "data[i].path"]
    set v_type [CkJsonObject_stringOf $jResp "data[i].type"]
    set extension [CkJsonObject_stringOf $jResp "data[i].extension"]
    set userId [CkJsonObject_IntOf $jResp "data[i].userId"]
    set created [CkJsonObject_stringOf $jResp "data[i].created"]
    set fileSize [CkJsonObject_IntOf $jResp "data[i].fileSize"]
    set width [CkJsonObject_stringOf $jResp "data[i].width"]
    set height [CkJsonObject_stringOf $jResp "data[i].height"]
    set attribute [CkJsonObject_stringOf $jResp "data[i].attribute"]
    set i [expr $i + 1]
}

delete_CkHttp $http
delete_CkStringBuilder $sbResponseBody
delete_CkJsonObject $jResp