Sample code for 30+ languages & platforms
React Native

Shopware List Categories

See more Shopware Examples

List categories in your Shopware database.

Chilkat React Native Downloads

React Native
import { Http, JsonObject, StringBuilder } from '@chilkat/react-native'

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

  const http = new Http();

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

  const sbResponseBody = new StringBuilder();
  try {
    await http.quickGetSbAsync('https://my-shopware-shop.com/api/categories?limit=2', sbResponseBody);
  } catch {
    console.log(http.lastErrorText);
    return;
  }

  const jResp = new JsonObject();
  jResp.loadSb(sbResponseBody);
  jResp.emitCompact = false;

  console.log('Response Body:');
  console.log(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

  let id = 0;
  let name = '';
  let position = 0;
  let parentId = '';
  let mediaId = '';
  let childrenCount = '';
  let articleCount = '';

  const total = jResp.intOf('total');
  jResp.boolOf('success');
  let i = 0;
  const 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++;
  }
}