C
C
Shopware List Media
See more Shopware Examples
Demonstrates how to get a list of media in Shopware.Chilkat C Downloads
#include <C_CkHttp.h>
#include <C_CkStringBuilder.h>
#include <C_CkJsonObject.h>
void ChilkatSample(void)
{
BOOL success;
HCkHttp http;
HCkStringBuilder sbResponseBody;
HCkJsonObject jResp;
int id;
int albumId;
const char *name;
const char *description;
const char *path;
const char *v_type;
const char *extension;
int userId;
const char *created;
int fileSize;
const char *width;
const char *height;
const char *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 = CkHttp_Create();
CkHttp_putLogin(http,"api_username");
CkHttp_putPassword(http,"api_key");
CkHttp_putBasicAuth(http,TRUE);
sbResponseBody = CkStringBuilder_Create();
success = CkHttp_QuickGetSb(http,"https://my-shopware-shop.com/api/media?limit=10",sbResponseBody);
if (success == FALSE) {
printf("%s\n",CkHttp_lastErrorText(http));
CkHttp_Dispose(http);
CkStringBuilder_Dispose(sbResponseBody);
return;
}
jResp = CkJsonObject_Create();
CkJsonObject_LoadSb(jResp,sbResponseBody);
CkJsonObject_putEmitCompact(jResp,FALSE);
printf("Response Body:\n");
printf("%s\n",CkJsonObject_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 = CkJsonObject_IntOf(jResp,"total");
success = CkJsonObject_BoolOf(jResp,"success");
i = 0;
count_i = CkJsonObject_SizeOfArray(jResp,"data");
while (i < count_i) {
CkJsonObject_putI(jResp,i);
id = CkJsonObject_IntOf(jResp,"data[i].id");
albumId = CkJsonObject_IntOf(jResp,"data[i].albumId");
name = CkJsonObject_stringOf(jResp,"data[i].name");
description = CkJsonObject_stringOf(jResp,"data[i].description");
path = CkJsonObject_stringOf(jResp,"data[i].path");
v_type = CkJsonObject_stringOf(jResp,"data[i].type");
extension = CkJsonObject_stringOf(jResp,"data[i].extension");
userId = CkJsonObject_IntOf(jResp,"data[i].userId");
created = CkJsonObject_stringOf(jResp,"data[i].created");
fileSize = CkJsonObject_IntOf(jResp,"data[i].fileSize");
width = CkJsonObject_stringOf(jResp,"data[i].width");
height = CkJsonObject_stringOf(jResp,"data[i].height");
attribute = CkJsonObject_stringOf(jResp,"data[i].attribute");
i = i + 1;
}
CkHttp_Dispose(http);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);
}