Sample code for 30+ languages & platforms
Unicode C

Shopware List Media

See more Shopware Examples

Demonstrates how to get a list of media in Shopware.

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;
    int albumId;
    const wchar_t *name;
    const wchar_t *description;
    const wchar_t *path;
    const wchar_t *v_type;
    const wchar_t *extension;
    int userId;
    const wchar_t *created;
    int fileSize;
    const wchar_t *width;
    const wchar_t *height;
    const wchar_t *attribute;
    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/media?limit=10",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": 6708,
    //        "albumId": -9,
    //        "name": "sonnenblume",
    //        "description": "",
    //        "path": "https:\/\/my-shopware-shop.com\/media\/pdf\/2f\/26\/52\/sonnenblume.zip",
    //        "type": "ARCHIVE",
    //        "extension": "zip",
    //        "userId": 5,
    //        "created": "2021-03-01T00:00:00+0100",
    //        "fileSize": 216905,
    //        "width": null,
    //        "height": null,
    //        "attribute": null
    //      },
    //      {
    //        "id": 6709,
    //        "albumId": -9,
    //        "name": "csinventur_anleitung",
    //        "description": "",
    //        "path": "https:\/\/my-shopware-shop.com\/media\/pdf\/19\/21\/86\/csinventur_anleitung.pdf",
    //        "type": "PDF",
    //        "extension": "pdf",
    //        "userId": 5,
    //        "created": "2021-03-01T00:00:00+0100",
    //        "fileSize": 837131,
    //        "width": null,
    //        "height": null,
    //        "attribute": null
    //      },
    //      {
    //        "id": 6710,
    //        "albumId": -9,
    //        "name": "photos_fre_carousel_elevatorpitch_620x252",
    //        "description": "",
    //        "path": "https:\/\/my-shopware-shop.com\/media\/pdf\/d8\/d7\/b4\/photos_fre_carousel_elevatorpitch_620x252.mp4",
    //        "type": "VIDEO",
    //        "extension": "mp4",
    //        "userId": 5,
    //        "created": "2021-03-01T00:00:00+0100",
    //        "fileSize": 2499157,
    //        "width": null,
    //        "height": null,
    //        "attribute": null
    //      },
    //  
    //  	...
    //    ],
    //    "total": 31,
    //    "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

    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");
        albumId = CkJsonObjectW_IntOf(jResp,L"data[i].albumId");
        name = CkJsonObjectW_stringOf(jResp,L"data[i].name");
        description = CkJsonObjectW_stringOf(jResp,L"data[i].description");
        path = CkJsonObjectW_stringOf(jResp,L"data[i].path");
        v_type = CkJsonObjectW_stringOf(jResp,L"data[i].type");
        extension = CkJsonObjectW_stringOf(jResp,L"data[i].extension");
        userId = CkJsonObjectW_IntOf(jResp,L"data[i].userId");
        created = CkJsonObjectW_stringOf(jResp,L"data[i].created");
        fileSize = CkJsonObjectW_IntOf(jResp,L"data[i].fileSize");
        width = CkJsonObjectW_stringOf(jResp,L"data[i].width");
        height = CkJsonObjectW_stringOf(jResp,L"data[i].height");
        attribute = CkJsonObjectW_stringOf(jResp,L"data[i].attribute");
        i = i + 1;
    }



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

    }