Sample code for 30+ languages & platforms
Unicode C

Shopware List Categories

See more Shopware Examples

List categories in your Shopware database.

Chilkat Unicode C Downloads

Unicode C
#include <C_CkHttpW.h>
#include <C_CkStringBuilderW.h>
#include <C_CkJsonObjectW.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkHttpW http;
    HCkStringBuilderW sbResponseBody;
    HCkJsonObjectW jResp;
    int id;
    BOOL active;
    const wchar_t *name;
    int position;
    const wchar_t *parentId;
    const wchar_t *mediaId;
    const wchar_t *childrenCount;
    const wchar_t *articleCount;
    int total;
    int i;
    int count_i;

    success = FALSE;

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

    http = CkHttpW_Create();

    CkHttpW_putLogin(http,L"api_username");
    CkHttpW_putPassword(http,L"api_key");
    CkHttpW_putBasicAuth(http,TRUE);

    sbResponseBody = CkStringBuilderW_Create();
    success = CkHttpW_QuickGetSb(http,L"https://my-shopware-shop.com/api/categories?limit=2",sbResponseBody);
    if (success == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkStringBuilderW_Dispose(sbResponseBody);
        return;
    }

    jResp = CkJsonObjectW_Create();
    CkJsonObjectW_LoadSb(jResp,sbResponseBody);
    CkJsonObjectW_putEmitCompact(jResp,FALSE);

    wprintf(L"Response Body:\n");
    wprintf(L"%s\n",CkJsonObjectW_emit(jResp));

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

    // Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.
    // See this example explaining how this memory should be used: const char * functions.

    total = CkJsonObjectW_IntOf(jResp,L"total");
    success = CkJsonObjectW_BoolOf(jResp,L"success");
    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"data");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        id = CkJsonObjectW_IntOf(jResp,L"data[i].id");
        active = CkJsonObjectW_BoolOf(jResp,L"data[i].active");
        name = CkJsonObjectW_stringOf(jResp,L"data[i].name");
        position = CkJsonObjectW_IntOf(jResp,L"data[i].position");
        parentId = CkJsonObjectW_stringOf(jResp,L"data[i].parentId");
        mediaId = CkJsonObjectW_stringOf(jResp,L"data[i].mediaId");
        childrenCount = CkJsonObjectW_stringOf(jResp,L"data[i].childrenCount");
        articleCount = CkJsonObjectW_stringOf(jResp,L"data[i].articleCount");
        i = i + 1;
    }



    CkHttpW_Dispose(http);
    CkStringBuilderW_Dispose(sbResponseBody);
    CkJsonObjectW_Dispose(jResp);

    }