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

Quickbooks Revoke OAuth2 Token

See more QuickBooks Examples

Demonstrates how to revoke a QuickBooks OAuth2 access token.

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.

    // This example assumes we previously obtained an OAuth2 access token for QuickBooks.

    const json_token = try chilkat.JsonObject.init();
    defer json_token.deinit();
    json_token.loadFile("qa_data/tokens/qb-access-token.json") catch {
        std.debug.print("Failed to load qb-access-token.json\n", .{});
        return;
    };

    // The access token JSON looks something like this:

    // {
    //   "expires_in": 3600,
    //   "x_refresh_token_expires_in": 8726400,
    //   "refresh_token": "L011546037639r ... 3vR2DrbOmg0Sdagw",
    //   "access_token": "eyJlbmMiOiJBMTI4Q0 ... oETJEMbeggg",
    //   "token_type": "bearer"
    // }

    // This code sends the following request:

    // POST https://developer.api.intuit.com/v2/oauth2/tokens/revoke HTTP/1.1
    // Accept: application/json
    // Authorization: Basic UTM0dVB...wM1d2
    // Content-Type: application/json
    //
    // {
    //     "token": "{bearerToken or refreshToken}"
    // }

    // Use this online tool to generate HTTP code from a sample request:
    // Generate Code from a Sample HTTP Request

    const http = try chilkat.Http.init();
    defer http.deinit();
    http.setRequestHeader("Accept", "application/json");
    http.setBasicAuth(true);
    http.setLogin("QUICKBOOKS-CLIENT-ID");
    http.setPassword("QUICKBOOKS-CLIENT-SECRET");

    const json = try chilkat.JsonObject.init();
    defer json.deinit();
    json.updateString("token", try json_token.stringOf(alloc, "access_token")) catch {};

    const url = "https://developer.api.intuit.com/v2/oauth2/tokens/revoke";
    const resp = try chilkat.HttpResponse.init();
    defer resp.deinit();
    http.httpJson("POST", url, json, "application/json", 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)});
}