Sample code for 30+ languages & platforms
Zig

BrickLink OAuth1 using Chilkat REST

See more BrickLink Examples

Demonstrates sending an api.bricklink.com request with OAuth1 authentication using Chilkat REST.

Note: This example requires Chilkat v9.5.0.91 or greater (due to adjustments made within Chilkat to support bricklink OAuth1 needs).

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 assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    const oauth1 = try chilkat.OAuth1.init();
    defer oauth1.deinit();

    oauth1.setConsumerKey("Your Consumer Key");
    oauth1.setConsumerSecret("Your Consumer Secret");
    oauth1.setToken("Your OAuth1 Token");
    oauth1.setTokenSecret("Your Token Secret");
    oauth1.setSignatureMethod("HMAC-SHA1");

    const rest = try chilkat.Rest.init();
    defer rest.deinit();

    rest.setAuthOAuth1(oauth1, false) catch {};

    rest.connect("api.bricklink.com", 443, true, true) catch {
        std.debug.print("{s}\n", .{try rest.getLastErrorText(alloc)});
        return;
    };

    const sb_response = try chilkat.StringBuilder.init();
    defer sb_response.deinit();
    rest.fullRequestNoBodySb("GET", "/api/store/v1/orders?direction=in", sb_response) catch {
        std.debug.print("{s}\n", .{try rest.getLastErrorText(alloc)});
        return;
    };

    std.debug.print("Response status code = {d}\n", .{rest.getResponseStatusCode()});

    const json = try chilkat.JsonObject.init();
    defer json.deinit();
    json.loadSb(sb_response) catch {};
    json.setEmitCompact(false);
    std.debug.print("{s}\n", .{try json.emit(alloc)});
}