Zig
Zig
Shopify Receive Count of All Products in a Collection
See more Shopify Examples
Get a count of all products of a given collectionChilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
const rest = try chilkat.Rest.init();
defer rest.deinit();
rest.setAuthBasic("SHOPIFY_PRIVATE_API_KEY", "SHOPIFY_PRIVATE_API_KEY") catch {};
rest.connect("chilkat.myshopify.com", 443, true, true) catch {
std.debug.print("{s}\n", .{try rest.getLastErrorText(alloc)});
return;
};
const sb_json = try chilkat.StringBuilder.init();
defer sb_json.deinit();
rest.fullRequestNoBodySb("GET", "/admin/products/count.json?collection_id=841564295 ", sb_json) catch {
std.debug.print("{s}\n", .{try rest.getLastErrorText(alloc)});
return;
};
if (rest.getResponseStatusCode() != 200) {
std.debug.print("Received error response code: {d}\n", .{rest.getResponseStatusCode()});
std.debug.print("Response body:\n", .{});
std.debug.print("{s}\n", .{try sb_json.getAsString(alloc)});
return;
}
const json = try chilkat.JsonObject.init();
defer json.deinit();
json.loadSb(sb_json) catch {};
// The following code parses the JSON response.
// A sample JSON response is shown below the sample code.
_ = json.intOf("count");
// A sample JSON response body that is parsed by the above code:
// {
// "count": 1
// }
std.debug.print("Example Completed.\n", .{});
}