Sample code for 30+ languages & platforms
Zig

SugarCRM Logout

See more SugarCRM Examples

Demonstrates how to logout of a session.

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

    var success: bool = false;

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

    rest.connect("your.site.domain", 443, true, true) catch {
        std.debug.print("{s}\n", .{try rest.getLastErrorText(alloc)});
        return;
    };

    rest.addHeader("Cache-Control", "no-cache") catch {};
    rest.addHeader("OAuth-Token", "<access_token>") catch {};

    const sb_req = try chilkat.StringBuilder.init();
    defer sb_req.deinit();

    const sb_json = try chilkat.StringBuilder.init();
    defer sb_json.deinit();
    rest.fullRequestSb("POST", "/rest/v10/oauth2/logout", sb_req, sb_json) catch {
        std.debug.print("{s}\n", .{try rest.getLastErrorText(alloc)});
        return;
    };

    if (rest.getResponseStatusCode() != 200) {
        std.debug.print("Received error response code: {d}\n", .{rest.getResponseStatusCode()});
        std.debug.print("Response body:\n", .{});
        std.debug.print("{s}\n", .{try sb_json.getAsString(alloc)});
        return;
    }

    const json = try chilkat.JsonObject.init();
    defer json.deinit();
    json.loadSb(sb_json) catch {};

    // The following code parses the JSON response.
    // A sample JSON response is shown below the sample code.

    success = json.boolOf("success");

    // A sample JSON response body that is parsed by the above code:

    // {
    //   "success": true
    // }

    std.debug.print("Example Completed.\n", .{});
}