Zig
Zig
Populi Add Financial Aid Disbursement
See more Populi Examples
Demonstrates the Populi addFinancialAidDisbursement task.Chilkat 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 assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// First load the previously obtained API token.
// See Get Populi Access Token for sample code showing how to get the API token.
const xml = try chilkat.Xml.init();
defer xml.deinit();
try xml.loadXmlFile("qa_data/tokens/populi_token.xml");
const access_key = xml.getChildContent(alloc, "access_key") catch {
std.debug.print("Did not find the access_key\n", .{});
return;
};
const rest = try chilkat.Rest.init();
defer rest.deinit();
// Connect using TLS.
// A single REST object, once connected, can be used for many Populi REST API calls.
// The auto-reconnect indicates that if the already-established HTTPS connection is closed,
// then it will be automatically re-established as needed.
const b_auto_reconnect = true;
rest.connect("yourcollege.populi.co", 443, true, b_auto_reconnect) catch {
std.debug.print("{s}\n", .{try rest.getLastErrorText(alloc)});
return;
};
rest.setAuthorization(access_key);
rest.addQueryParam("task", "addFinancialAidDisbursement") catch {};
rest.addQueryParam("person_id", "12345678") catch {};
rest.addQueryParam("award_id", "555555") catch {};
rest.addQueryParam("academic_term_id", "123") catch {};
rest.addQueryParam("scheduled_date", "2019-10-10") catch {};
rest.addQueryParam("amount", "12345") catch {};
const response_body = rest.fullRequestFormUrlEncoded(alloc, "POST", "/api/index.php") catch {
std.debug.print("{s}\n", .{try rest.getLastErrorText(alloc)});
return;
};
// We should expect a 200 response if successful.
if (rest.getResponseStatusCode() != 200) {
std.debug.print("Request Header: \n", .{});
std.debug.print("{s}\n", .{try rest.getLastRequestHeader(alloc)});
std.debug.print("----\n", .{});
std.debug.print("Response StatusCode = {d}\n", .{rest.getResponseStatusCode()});
std.debug.print("Response StatusLine: {s}\n", .{try rest.getResponseStatusText(alloc)});
std.debug.print("Response Header:\n", .{});
std.debug.print("{s}\n", .{try rest.getResponseHeader(alloc)});
std.debug.print("Response Body:\n", .{});
std.debug.print("{s}\n", .{response_body});
return;
}
xml.loadXml(response_body) catch {};
std.debug.print("{s}\n", .{try xml.getXml(alloc)});
// Sample response:
// Use this online tool to generate parsing code from sample XML:
// Generate Parsing Code from XML
// <?xml version="1.0" encoding="UTF-8"?>
// <result>
// <disbursement>123456</disbursement>
// </result>
_ = xml.getChildIntValue("disbursement");
}