Zig Requires Chilkat v11.0.0+
Zig
Xero Get Payroll Employees
See more Xero Examples
Download Xero employees informationChilkat 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"));
// Replace the value here with an actual tenant ID obtained from this example:
// Get Xero Tenant IDs
http.setRequestHeader("Xero-tenant-id", "83299b9e-5747-4a14-a18a-a6c94f824eb7");
http.setAccept("application/json");
const resp = try chilkat.HttpResponse.init();
defer resp.deinit();
http.httpNoBody("GET", "https://api.xero.com/payroll.xro/1.0/Employees", resp) catch {
std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
return;
};
std.debug.print("Response Status Code: {d}\n", .{resp.getStatusCode()});
const json = try chilkat.JsonObject.init();
defer json.deinit();
json.load(try resp.getBodyStr(alloc)) catch {};
json.setEmitCompact(false);
std.debug.print("{s}\n", .{try json.emit(alloc)});
if (resp.getStatusCode() != 200) {
std.debug.print("Failed.\n", .{});
return;
}
// Sample response
// (See the parsing code below..)
//
// Use the this online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
// {
// "Id": "796cae61-a7c3-425b-a621-372ab1f29460",
// "Status": "OK",
// "ProviderName": "Chilkat2222",
// "DateTimeUTC": "\/Date(1587075322768)\/",
// "Employees": [
// {
// "EmployeeID": "f12e3b0b-4b4c-4523-b8c0-f481a07bfd13",
// "FirstName": "James",
// "LastName": "Lebron",
// "Status": "ACTIVE",
// "Email": "JL@madeup.email.com",
// "DateOfBirth": "\/Date(492739200000+0000)\/",
// "Gender": "M",
// "Phone": "0400-000-123",
// "Mobile": " 408-230-9732",
// "StartDate": "\/Date(1548806400000+0000)\/",
// "OrdinaryEarningsRateID": "e648f7bf-af43-41bc-98ea-e7ca94c3e3b1",
// "PayrollCalendarID": "2cf6326a-d48b-41bf-bf36-7a73b42dd71b",
// "UpdatedDateUTC": "\/Date(1587075120000+0000)\/"
// },
// {
// "EmployeeID": "d9f5979f-1de8-4040-aa1d-f1fdd327f893",
// "FirstName": "Odette",
// "LastName": "Garrison",
// "Status": "ACTIVE",
// "Email": "ogg@madeup.email.com",
// "DateOfBirth": "\/Date(390528000000+0000)\/",
// "Gender": "F",
// "Phone": "9000 1234",
// "StartDate": "\/Date(1554422400000+0000)\/",
// "OrdinaryEarningsRateID": "e648f7bf-af43-41bc-98ea-e7ca94c3e3b1",
// "PayrollCalendarID": "ec0f2f68-f4d1-4490-af70-78e5d7f5dcbd",
// "UpdatedDateUTC": "\/Date(1587075120000+0000)\/"
// },
// {
// "EmployeeID": "22879fb4-d13b-46ed-9c07-e43aba25b576",
// "FirstName": "Oliver",
// "LastName": "Gray",
// "Status": "ACTIVE",
// "Email": "og@madeup.email.com",
// "DateOfBirth": "\/Date(94176000000+0000)\/",
// "Gender": "M",
// "Phone": "0401 123 456",
// "StartDate": "\/Date(1562112000000+0000)\/",
// "OrdinaryEarningsRateID": "e648f7bf-af43-41bc-98ea-e7ca94c3e3b1",
// "PayrollCalendarID": "2cf6326a-d48b-41bf-bf36-7a73b42dd71b",
// "UpdatedDateUTC": "\/Date(1587075120000+0000)\/"
// },
// {
// "EmployeeID": "c4d82c18-b1a9-4b6c-982c-14b45b95c10a",
// "FirstName": "Sally ",
// "LastName": "Martin",
// "Status": "ACTIVE",
// "Email": "sm@madeup3993.com",
// "DateOfBirth": "\/Date(659577600000+0000)\/",
// "Gender": "F",
// "Phone": "0400 123 456",
// "StartDate": "\/Date(1577750400000+0000)\/",
// "OrdinaryEarningsRateID": "e648f7bf-af43-41bc-98ea-e7ca94c3e3b1",
// "PayrollCalendarID": "2cf6326a-d48b-41bf-bf36-7a73b42dd71b",
// "UpdatedDateUTC": "\/Date(1587075120000+0000)\/"
// },
// {
// "EmployeeID": "e1a5eed0-721e-482d-b1f1-0b73506f26fb",
// "FirstName": "Sonia",
// "LastName": "Michaels",
// "Status": "ACTIVE",
// "Email": "som@madeup3993.com",
// "DateOfBirth": "\/Date(727660800000+0000)\/",
// "Gender": "F",
// "Phone": "02 2345 6789",
// "Mobile": " ",
// "UpdatedDateUTC": "\/Date(1587075120000+0000)\/"
// },
// {
// "EmployeeID": "882587ac-1cfe-4f55-9b37-932b0705cd04",
// "FirstName": "Tracy",
// "LastName": "Green",
// "Status": "ACTIVE",
// "Email": "tg@madeup.email.com",
// "DateOfBirth": "\/Date(712886400000+0000)\/",
// "Gender": "F",
// "Phone": "0402 123 456",
// "StartDate": "\/Date(1556755200000+0000)\/",
// "OrdinaryEarningsRateID": "e648f7bf-af43-41bc-98ea-e7ca94c3e3b1",
// "PayrollCalendarID": "ec0f2f68-f4d1-4490-af70-78e5d7f5dcbd",
// "UpdatedDateUTC": "\/Date(1587075120000+0000)\/"
// }
// ]
// }
var employee_id: [:0]const u8 = "";
var first_name: [:0]const u8 = "";
var last_name: [:0]const u8 = "";
var v_email: [:0]const u8 = "";
var date_of_birth: [:0]const u8 = "";
var gender: [:0]const u8 = "";
var phone: [:0]const u8 = "";
var mobile: [:0]const u8 = "";
var start_date: [:0]const u8 = "";
var ordinary_earnings_rate_id: [:0]const u8 = "";
var payroll_calendar_id: [:0]const u8 = "";
var updated_date_utc: [:0]const u8 = "";
_ = try json.stringOf(alloc, "Id");
var status: [:0]const u8 = try json.stringOf(alloc, "Status");
_ = try json.stringOf(alloc, "ProviderName");
_ = try json.stringOf(alloc, "DateTimeUTC");
var i: i32 = 0;
const count_i = json.sizeOfArray("Employees");
while (i < count_i) {
json.setI(i);
employee_id = try json.stringOf(alloc, "Employees[i].EmployeeID");
first_name = try json.stringOf(alloc, "Employees[i].FirstName");
last_name = try json.stringOf(alloc, "Employees[i].LastName");
status = try json.stringOf(alloc, "Employees[i].Status");
v_email = try json.stringOf(alloc, "Employees[i].Email");
date_of_birth = try json.stringOf(alloc, "Employees[i].DateOfBirth");
gender = try json.stringOf(alloc, "Employees[i].Gender");
phone = try json.stringOf(alloc, "Employees[i].Phone");
mobile = try json.stringOf(alloc, "Employees[i].Mobile");
start_date = try json.stringOf(alloc, "Employees[i].StartDate");
ordinary_earnings_rate_id = try json.stringOf(alloc, "Employees[i].OrdinaryEarningsRateID");
payroll_calendar_id = try json.stringOf(alloc, "Employees[i].PayrollCalendarID");
updated_date_utc = try json.stringOf(alloc, "Employees[i].UpdatedDateUTC");
i = i + 1;
}
}