Sample code for 30+ languages & platforms
Xbase++

Shopware List Categories

See more Shopware Examples

List categories in your Shopware database.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oHttp
LOCAL oSbResponseBody
LOCAL oJResp
LOCAL nId
LOCAL nActive
LOCAL cName
LOCAL nPosition
LOCAL cParentId
LOCAL cMediaId
LOCAL cChildrenCount
LOCAL cArticleCount
LOCAL nTotal
LOCAL i
LOCAL nCount_i

nSuccess := 0

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

oHttp := CreateObject("Chilkat.Http")

oHttp:Login := "api_username"
oHttp:Password := "api_key"
oHttp:BasicAuth := 1

oSbResponseBody := CreateObject("Chilkat.StringBuilder")
nSuccess := oHttp:QuickGetSb("https://my-shopware-shop.com/api/categories?limit=2", oSbResponseBody)
IF (nSuccess == 0)
    ? oHttp:LastErrorText
    oHttp:destroy()
    oSbResponseBody:destroy()
    RETURN
ENDIF

oJResp := CreateObject("Chilkat.JsonObject")
oJResp:LoadSb(oSbResponseBody)
oJResp:EmitCompact := 0

? "Response Body:"
? oJResp: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

nTotal := oJResp:IntOf("total")
nSuccess := oJResp:BoolOf("success")
i := 0
nCount_i := oJResp:SizeOfArray("data")
DO WHILE i < nCount_i
    oJResp:I := i
    nId := oJResp:IntOf("data[i].id")
    nActive := oJResp:BoolOf("data[i].active")
    cName := oJResp:StringOf("data[i].name")
    nPosition := oJResp:IntOf("data[i].position")
    cParentId := oJResp:StringOf("data[i].parentId")
    cMediaId := oJResp:StringOf("data[i].mediaId")
    cChildrenCount := oJResp:StringOf("data[i].childrenCount")
    cArticleCount := oJResp:StringOf("data[i].articleCount")
    i := i + 1
ENDDO

oHttp:destroy()
oSbResponseBody:destroy()
oJResp:destroy()