Sample code for 30+ languages & platforms
Swift

Shopware List Categories

See more Shopware Examples

List categories in your Shopware database.

Chilkat Swift Downloads

Swift

func chilkatTest() {
    var success: Bool = false

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

    let http = CkoHttp()!

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

    let sbResponseBody = CkoStringBuilder()!
    success = http.quickGetSb(url: "https://my-shopware-shop.com/api/categories?limit=2", sbContent: sbResponseBody)
    if success == false {
        print("\(http.lastErrorText!)")
        return
    }

    let jResp = CkoJsonObject()!
    jResp.loadSb(sb: sbResponseBody)
    jResp.emitCompact = 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

    var id: Int
    var active: Bool
    var name: String?
    var position: Int
    var parentId: String?
    var mediaId: String?
    var childrenCount: String?
    var articleCount: String?

    var total: Int = jResp.int(of: "total").intValue
    success = jResp.bool(of: "success")
    var i: Int = 0
    var count_i: Int = jResp.size(ofArray: "data").intValue
    while i < count_i {
        jResp.i = i
        id = jResp.int(of: "data[i].id").intValue
        active = jResp.bool(of: "data[i].active")
        name = jResp.string(of: "data[i].name")
        position = jResp.int(of: "data[i].position").intValue
        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
    }


}