Sample code for 30+ languages & platforms
Lua

Shopware List Categories

See more Shopware Examples

List categories in your Shopware database.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

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

local http = chilkat.Http.new()

http.login = "api_username"
http.password = "api_key"
http.basic_auth = true

local sbResponseBody = chilkat.StringBuilder.new()
local success = http:quick_get_sb("https://my-shopware-shop.com/api/categories?limit=2", sbResponseBody)
if not success then
    print(http.last_error_text)
    return
end

local jResp = chilkat.JsonObject.new()
jResp:load_sb(sbResponseBody)
jResp.emit_compact = false

print("Response Body:")
print(jResp:emit())

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

local id = 0
local active = false
local name = ""
local position = 0
local parentId = ""
local mediaId = ""
local childrenCount = ""
local articleCount = ""

local total = jResp:int_of("total")
success = jResp:bool_of("success")
local i = 0
local count_i = jResp:size_of_array("data")
while i < count_i do
    jResp.i = i
    id = jResp:int_of("data[i].id")
    active = jResp:bool_of("data[i].active")
    name = jResp:string_of("data[i].name")
    position = jResp:int_of("data[i].position")
    parentId = jResp:string_of("data[i].parentId")
    mediaId = jResp:string_of("data[i].mediaId")
    childrenCount = jResp:string_of("data[i].childrenCount")
    articleCount = jResp:string_of("data[i].articleCount")
    i = i + 1
end