Sample code for 30+ languages & platforms
Zig

qa.factura1.com.co Obtain Auth Token

See more HTTP Misc Examples

Demonstrates how to send a JSON POST to get an authenticataion token for qa.factura1.com.co

Chilkat Zig Downloads

Zig
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();

    // Build the following JSON
    // {
    //   "password": "MY_PASSWORD",
    //   "username": "MY_USERNAME"
    // }

    const json = try chilkat.JsonObject.init();
    defer json.deinit();
    json.setEmitCompact(false);
    json.updateString("password", "MY_PASSWORD") catch {};
    json.updateString("username", "MY_USERNAME") catch {};

    const resp = try chilkat.HttpResponse.init();
    defer resp.deinit();
    http.httpJson("POST", "https://qa.factura1.com.co/v2/auth", json, "application/json", resp) catch {
        std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
        return;
    };

    const json_resp = try chilkat.JsonObject.init();
    defer json_resp.deinit();
    json_resp.setEmitCompact(false);
    json_resp.load(try resp.getBodyStr(alloc)) catch {};

    std.debug.print("{s}\n", .{try json_resp.emit(alloc)});

    std.debug.print("Access token: {s}\n", .{try json_resp.stringOf(alloc, "token")});
}