Sample code for 30+ languages & platforms
Zig Requires Chilkat v11.0.0+

BrickLink OAuth1 using Chilkat HTTP

See more BrickLink Examples

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

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 http = try chilkat.Http.init();
    defer http.deinit();

    http.setOAuth1(true);
    http.setOAuthConsumerKey("Your Consumer Key");
    http.setOAuthConsumerSecret("Your Consumer Secret");
    http.setOAuthToken("Your OAuth1 Token");
    http.setOAuthTokenSecret("Your Token Secret");
    http.setOAuthSigMethod("HMAC-SHA1");

    const resp = try chilkat.HttpResponse.init();
    defer resp.deinit();
    http.httpNoBody("GET", "https://api.bricklink.com/api/store/v1/orders?direction=in", 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();
    resp.getBodyJson(json) catch {};

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