Sample code for 30+ languages & platforms
Zig

DocuSign List Folders

See more DocuSign Examples

Retrieves a list of the folders for the account, including the folder hierarchy. You can specify type kinds of folders to return with the include query parameter.

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

    // Implements the following HTTP request:
    // GET /restapi/v2.1/accounts/{accountId}/folders

    // Adds the "Authorization: Bearer eyJ0eXAi.....UE8Kl_V8KroQ" header.
    const json_token = try chilkat.JsonObject.init();
    defer json_token.deinit();
    // Load a previously obtained OAuth2 access token.
    json_token.loadFile("qa_data/tokens/docusign.json") catch {
        std.debug.print("{s}\n", .{try json_token.getLastErrorText(alloc)});
        return;
    };

    http.setAuthToken(try json_token.stringOf(alloc, "access_token"));

    // Use your account ID here:
    http.setUrlVar("accountId", "7f3f65ed-5e87-418d-94c1-92499ddc8252") catch {};

    const sb_response_body = try chilkat.StringBuilder.init();
    defer sb_response_body.deinit();
    http.quickGetSb("https://demo.docusign.net/restapi/v2.1/accounts/{$accountId}/folders", sb_response_body) catch {
        std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
        return;
    };

    const j_resp = try chilkat.JsonObject.init();
    defer j_resp.deinit();
    j_resp.loadSb(sb_response_body) catch {};
    j_resp.setEmitCompact(false);

    std.debug.print("Response Body:\n", .{});
    std.debug.print("{s}\n", .{try j_resp.emit(alloc)});

    const resp_status_code = http.getLastStatus();
    std.debug.print("Response Status Code = {d}\n", .{resp_status_code});
    if (resp_status_code >= 400) {
        std.debug.print("Response Header:\n", .{});
        std.debug.print("{s}\n", .{try http.getLastHeader(alloc)});
        std.debug.print("Failed.\n", .{});
        return;
    }

    // Sample JSON response:
    // (Sample code for parsing the JSON response is shown below)

    // {
    //   "resultSetSize": "4",
    //   "startPosition": "0",
    //   "endPosition": "3",
    //   "totalSetSize": "4",
    //   "folders": [
    //     {
    //       "name": "Draft",
    //       "type": "draft",
    //       "owner": {
    //         "userName": "Joe Sample",
    //         "userId": "14602117-2430-4582-8a49-ba8766302272",
    //         "email": "admin@chilkatsoft.com"
    //       },
    //       "folderId": "f0bc5174-610d-4d80-80d7-91037843ccdb",
    //       "uri": "/folders/f0bc5174-610d-4d80-80d7-91037843ccdb",
    //       "itemCount": "0",
    //       "subFolderCount": "0",
    //       "hasSubFolders": "false"
    //     },
    //     {
    //       "name": "Inbox",
    //       "type": "inbox",
    //       "owner": {
    //         "userName": "Joe Sample",
    //         "userId": "14602117-2430-4582-8a49-ba8766302272",
    //         "email": "admin@chilkatsoft.com"
    //       },
    //       "folderId": "06c97346-f7b4-46fd-a204-038287d655ec",
    //       "uri": "/folders/06c97346-f7b4-46fd-a204-038287d655ec",
    //       "itemCount": "1",
    //       "subFolderCount": "0",
    //       "hasSubFolders": "false"
    //     },
    //     {
    //       "name": "Deleted Items",
    //       "type": "recyclebin",
    //       "owner": {
    //         "userName": "Joe Sample",
    //         "userId": "14602117-2430-4582-8a49-ba8766302272",
    //         "email": "admin@chilkatsoft.com"
    //       },
    //       "folderId": "6df0919e-b152-49fc-a4c9-9b430a29d4f5",
    //       "uri": "/folders/6df0919e-b152-49fc-a4c9-9b430a29d4f5",
    //       "itemCount": "0",
    //       "subFolderCount": "0",
    //       "hasSubFolders": "false"
    //     },
    //     {
    //       "name": "Sent Items",
    //       "type": "sentitems",
    //       "owner": {
    //         "userName": "Joe Sample",
    //         "userId": "14602117-2430-4582-8a49-ba8766302272",
    //         "email": "admin@chilkatsoft.com"
    //       },
    //       "folderId": "456f3c76-b265-4453-a024-c39b1a5cb387",
    //       "uri": "/folders/456f3c76-b265-4453-a024-c39b1a5cb387",
    //       "itemCount": "1",
    //       "subFolderCount": "0",
    //       "hasSubFolders": "false"
    //     }
    //   ]
    // }

    // Sample code for parsing the JSON response...
    // Use the following online tool to generate parsing code from sample JSON:
    // Generate Parsing Code from JSON

    var name: [:0]const u8 = "";
    var v_type: [:0]const u8 = "";
    var owner_user_name: [:0]const u8 = "";
    var owner_user_id: [:0]const u8 = "";
    var owner_email: [:0]const u8 = "";
    var folder_id: [:0]const u8 = "";
    var uri: [:0]const u8 = "";
    var item_count: [:0]const u8 = "";
    var sub_folder_count: [:0]const u8 = "";
    var has_sub_folders: [:0]const u8 = "";

    _ = try j_resp.stringOf(alloc, "resultSetSize");
    _ = try j_resp.stringOf(alloc, "startPosition");
    _ = try j_resp.stringOf(alloc, "endPosition");
    _ = try j_resp.stringOf(alloc, "totalSetSize");
    var i: i32 = 0;
    const count_i = j_resp.sizeOfArray("folders");
    while (i < count_i) {
        j_resp.setI(i);
        name = try j_resp.stringOf(alloc, "folders[i].name");
        v_type = try j_resp.stringOf(alloc, "folders[i].type");
        owner_user_name = try j_resp.stringOf(alloc, "folders[i].owner.userName");
        owner_user_id = try j_resp.stringOf(alloc, "folders[i].owner.userId");
        owner_email = try j_resp.stringOf(alloc, "folders[i].owner.email");
        folder_id = try j_resp.stringOf(alloc, "folders[i].folderId");
        uri = try j_resp.stringOf(alloc, "folders[i].uri");
        item_count = try j_resp.stringOf(alloc, "folders[i].itemCount");
        sub_folder_count = try j_resp.stringOf(alloc, "folders[i].subFolderCount");
        has_sub_folders = try j_resp.stringOf(alloc, "folders[i].hasSubFolders");
        i = i + 1;
    }
}