Zig Requires Chilkat v11.0.0+
Zig
Xero Get Full Set of Tenants
See more Xero Examples
Check the full set of tenants you've been authorized to accessChilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const http = try chilkat.Http.init();
defer http.deinit();
const json_token = try chilkat.JsonObject.init();
defer json_token.deinit();
json_token.loadFile("qa_data/tokens/xero-access-token.json") catch {
std.debug.print("{s}\n", .{try json_token.getLastErrorText(alloc)});
return;
};
http.setAuthToken(try json_token.stringOf(alloc, "access_token"));
http.setAccept("application/json");
const resp = try chilkat.HttpResponse.init();
defer resp.deinit();
http.httpNoBody("GET", "https://api.xero.com/connections", resp) catch {
std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
return;
};
std.debug.print("Response Status Code: {d}\n", .{resp.getStatusCode()});
const jarr = try chilkat.JsonArray.init();
defer jarr.deinit();
jarr.load(try resp.getBodyStr(alloc)) catch {};
jarr.setEmitCompact(false);
std.debug.print("{s}\n", .{try jarr.emit(alloc)});
if (resp.getStatusCode() != 200) {
std.debug.print("Failed.\n", .{});
return;
}
// Sample response
// Use this online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
// [
// {
// "id": "c869f3b7-6435-4c7e-8cb2-122721b04a69",
// "tenantId": "45e4708e-d862-4111-ab3a-dd8cd03913e1",
// "tenantType": "ORGANISATION",
// "createdDateUtc": "2020-02-02T19:17:58.1117990",
// "updatedDateUtc": "2020-02-02T19:17:58.1117990"
// },
// {
// "id": "74305bf3-12e0-45e2-8dc8-e3ec73e3b1f9",
// "tenantId": "c3d5e782-2153-4cda-bdb4-cec791ceb90d",
// "tenantType": "ORGANISATION",
// "createdDateUtc": "2020-01-30T01:33:36.2717380",
// "updatedDateUtc": "2020-02-02T19:21:08.5739590"
// }
// ]
var id: [:0]const u8 = "";
var tenant_id: [:0]const u8 = "";
var tenant_type: [:0]const u8 = "";
var created_date_utc: [:0]const u8 = "";
var updated_date_utc: [:0]const u8 = "";
var i: i32 = 0;
const count_i = jarr.getSize();
while (i < count_i) {
const json = try jarr.objectAt(i);
defer json.deinit();
id = try json.stringOf(alloc, "id");
tenant_id = try json.stringOf(alloc, "tenantId");
tenant_type = try json.stringOf(alloc, "tenantType");
created_date_utc = try json.stringOf(alloc, "createdDateUtc");
updated_date_utc = try json.stringOf(alloc, "updatedDateUtc");
i = i + 1;
}
}