Sample code for 30+ languages & platforms
Delphi DLL

Shopware List Media

See more Shopware Examples

Demonstrates how to get a list of media in Shopware.

Chilkat Delphi DLL Downloads

Delphi DLL
uses
    Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
    Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Http, StringBuilder, JsonObject;

...

procedure TForm1.Button1Click(Sender: TObject);
var
success: Boolean;
http: HCkHttp;
sbResponseBody: HCkStringBuilder;
jResp: HCkJsonObject;
id: Integer;
albumId: Integer;
name: PWideChar;
description: PWideChar;
path: PWideChar;
v_type: PWideChar;
extension: PWideChar;
userId: Integer;
created: PWideChar;
fileSize: Integer;
width: PWideChar;
height: PWideChar;
attribute: PWideChar;
total: Integer;
i: Integer;
count_i: Integer;

begin
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) then
  begin
    Memo1.Lines.Add(CkHttp__lastErrorText(http));
    Exit;
  end;

jResp := CkJsonObject_Create();
CkJsonObject_LoadSb(jResp,sbResponseBody);
CkJsonObject_putEmitCompact(jResp,False);

Memo1.Lines.Add('Response Body:');
Memo1.Lines.Add(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 do
  begin
    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;
  end;

CkHttp_Dispose(http);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);

end;