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 <CkHttpW.h>
#include <CkStringBuilderW.h>
#include <CkJsonObjectW.h>

void ChilkatSample(void)
    {
    bool success = false;

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

    CkHttpW http;

    http.put_Login(L"api_username");
    http.put_Password(L"api_key");
    http.put_BasicAuth(true);

    CkStringBuilderW sbResponseBody;
    success = http.QuickGetSb(L"https://my-shopware-shop.com/api/media?limit=10",sbResponseBody);
    if (success == false) {
        wprintf(L"%s\n",http.lastErrorText());
        return;
    }

    CkJsonObjectW jResp;
    jResp.LoadSb(sbResponseBody);
    jResp.put_EmitCompact(false);

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

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

    int id;
    int albumId;
    const wchar_t *name = 0;
    const wchar_t *description = 0;
    const wchar_t *path = 0;
    const wchar_t *v_type = 0;
    const wchar_t *extension = 0;
    int userId;
    const wchar_t *created = 0;
    int fileSize;
    const wchar_t *width = 0;
    const wchar_t *height = 0;
    const wchar_t *attribute = 0;

    int total = jResp.IntOf(L"total");
    success = jResp.BoolOf(L"success");
    int i = 0;
    int count_i = jResp.SizeOfArray(L"data");
    while (i < count_i) {
        jResp.put_I(i);
        id = jResp.IntOf(L"data[i].id");
        albumId = jResp.IntOf(L"data[i].albumId");
        name = jResp.stringOf(L"data[i].name");
        description = jResp.stringOf(L"data[i].description");
        path = jResp.stringOf(L"data[i].path");
        v_type = jResp.stringOf(L"data[i].type");
        extension = jResp.stringOf(L"data[i].extension");
        userId = jResp.IntOf(L"data[i].userId");
        created = jResp.stringOf(L"data[i].created");
        fileSize = jResp.IntOf(L"data[i].fileSize");
        width = jResp.stringOf(L"data[i].width");
        height = jResp.stringOf(L"data[i].height");
        attribute = jResp.stringOf(L"data[i].attribute");
        i = i + 1;
    }
    }