Zig
Zig
Shopware List Categories
See more Shopware Examples
List categories in your Shopware database.Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
var success: bool = false;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const http = try chilkat.Http.init();
defer http.deinit();
http.setLogin("api_username");
http.setPassword("api_key");
http.setBasicAuth(true);
const sb_response_body = try chilkat.StringBuilder.init();
defer sb_response_body.deinit();
http.quickGetSb("https://my-shopware-shop.com/api/categories?limit=2", sb_response_body) catch {
std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
return;
};
const j_resp = try chilkat.JsonObject.init();
defer j_resp.deinit();
j_resp.loadSb(sb_response_body) catch {};
j_resp.setEmitCompact(false);
std.debug.print("Response Body:\n", .{});
std.debug.print("{s}\n", .{try j_resp.emit(alloc)});
// 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
var id: i32 = 0;
var active: bool = false;
var name: [:0]const u8 = "";
var position: i32 = 0;
var parent_id: [:0]const u8 = "";
var media_id: [:0]const u8 = "";
var children_count: [:0]const u8 = "";
var article_count: [:0]const u8 = "";
_ = j_resp.intOf("total");
success = j_resp.boolOf("success");
var i: i32 = 0;
const count_i = j_resp.sizeOfArray("data");
while (i < count_i) {
j_resp.setI(i);
id = j_resp.intOf("data[i].id");
active = j_resp.boolOf("data[i].active");
name = try j_resp.stringOf(alloc, "data[i].name");
position = j_resp.intOf("data[i].position");
parent_id = try j_resp.stringOf(alloc, "data[i].parentId");
media_id = try j_resp.stringOf(alloc, "data[i].mediaId");
children_count = try j_resp.stringOf(alloc, "data[i].childrenCount");
article_count = try j_resp.stringOf(alloc, "data[i].articleCount");
i = i + 1;
}
}