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

NetSuite OAuth1

See more OAuth1 Examples

Demonstrates adding OAUth1 authentication to a NetSuite REST API request.

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

    // It 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();

    http.setOAuth1(true);
    http.setOAuthConsumerKey("CONSUMER_KEY");
    http.setOAuthConsumerSecret("CONSUMER_SECRET");
    http.setOAuthToken("ACCESS_TOKEN");
    http.setOAuthTokenSecret("TOKEN_SECRET");
    http.setOAuthRealm("ACCOUNT_ID");
    http.setOAuthSigMethod("HMAC-SHA256");

    // Not sure if this is needed for NetSuite requests.
    http.setRequestHeader("Cookie", "NS_ROUTING_VERSION=LAGGING");

    // Replace ACCOUNT_ID with your actual account id, which is likely a 7-digit decimal number.
    const resp = try chilkat.HttpResponse.init();
    defer resp.deinit();
    http.httpNoBody("GET", "https://ACCOUNT_ID.suitetalk.api.netsuite.com/services/rest/record/v1/salesOrder", resp) catch {
        std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
        return;
    };

    std.debug.print("Response Status Code: {d}\n", .{resp.getStatusCode()});
    std.debug.print("Response Body:\n", .{});
    std.debug.print("{s}\n", .{try resp.getBodyStr(alloc)});
}