Sample code for 30+ languages & platforms
Dart

Shopware List Categories

See more Shopware Examples

List categories in your Shopware database.

Chilkat Dart Downloads

Dart
import 'package:chilkat/chilkat.dart';

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

  final http = CkHttp();

  http.login = 'api_username';
  http.password = 'api_key';
  http.basicAuth = true;

  final sbResponseBody = CkStringBuilder();
  try {
    http.quickGetSb('https://my-shopware-shop.com/api/categories?limit=2', sbResponseBody);
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  final jResp = CkJsonObject();
  jResp.loadSb(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 = 0;
  var name = '';
  var position = 0;
  var parentId = '';
  var mediaId = '';
  var childrenCount = '';
  var articleCount = '';

  final total = jResp.intOf('total');
  jResp.boolOf('success');
  var i = 0;
  final countI = jResp.sizeOfArray('data');
  while (i < countI) {
    jResp.i = i;
    id = jResp.intOf('data[i].id');
    jResp.boolOf('data[i].active');
    name = jResp.stringOf('data[i].name');
    position = jResp.intOf('data[i].position');
    parentId = jResp.stringOf('data[i].parentId');
    mediaId = jResp.stringOf('data[i].mediaId');
    childrenCount = jResp.stringOf('data[i].childrenCount');
    articleCount = jResp.stringOf('data[i].articleCount');
    i++;
  }
}