Sample code for 30+ languages & platforms
Zig

DocuSign List Folder Items

See more DocuSign Examples

Retrieves a list of the envelopes in the specified folder.

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/{folderId}

    // 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 and a valid folderId here:
    http.setUrlVar("accountId", "7f3f65ed-5e87-418d-94c1-92499ddc8252") catch {};
    http.setUrlVar("folderId", "94644782-31b7-4f82-a2c1-26d8a9306f8c") 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/{$folderId}", 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.getLastResponseHeader(alloc)});
        std.debug.print("Failed.\n", .{});
        return;
    }

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

    // {
    //   "resultSetSize": "sample string 1",
    //   "startPosition": "sample string 2",
    //   "endPosition": "sample string 3",
    //   "totalSetSize": "sample string 4",
    //   "previousUri": "sample string 5",
    //   "nextUri": "sample string 6",
    //   "folderItems": [
    //     {
    //       "ownerName": "sample string 1",
    //       "envelopeId": "sample string 2",
    //       "envelopeUri": "sample string 3",
    //       "status": "sample string 4",
    //       "senderName": "sample string 5",
    //       "senderEmail": "sample string 6",
    //       "createdDateTime": "sample string 7",
    //       "sentDateTime": "sample string 8",
    //       "completedDateTime": "sample string 9",
    //       "subject": "sample string 10",
    //       "templateId": "sample string 11",
    //       "name": "sample string 12",
    //       "shared": "sample string 13",
    //       "password": "sample string 14",
    //       "description": "sample string 15",
    //       "lastModified": "sample string 16",
    //       "pageCount": 17,
    //       "uri": "sample string 18",
    //       "is21CFRPart11": "sample string 19",
    //       "isSignatureProviderEnvelope": "sample string 20",
    //       "customFields": [
    //         {
    //           "fieldId": "sample string 1",
    //           "name": "sample string 2",
    //           "show": "sample string 3",
    //           "required": "sample string 4",
    //           "value": "sample string 5",
    //           "configurationType": "sample string 6",
    //           "errorDetails": {
    //             "errorCode": "sample string 1",
    //             "message": "sample string 2"
    //           }
    //         }
    //       ]
    //     }
    //   ]
    // }

    // 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 owner_name: [:0]const u8 = "";
    var envelope_id: [:0]const u8 = "";
    var envelope_uri: [:0]const u8 = "";
    var status: [:0]const u8 = "";
    var sender_name: [:0]const u8 = "";
    var sender_email: [:0]const u8 = "";
    var created_date_time: [:0]const u8 = "";
    var sent_date_time: [:0]const u8 = "";
    var completed_date_time: [:0]const u8 = "";
    var subject: [:0]const u8 = "";
    var template_id: [:0]const u8 = "";
    var name: [:0]const u8 = "";
    var shared: [:0]const u8 = "";
    var password: [:0]const u8 = "";
    var description: [:0]const u8 = "";
    var last_modified: [:0]const u8 = "";
    var page_count: i32 = 0;
    var uri: [:0]const u8 = "";
    var is21_cfr_part11: [:0]const u8 = "";
    var is_signature_provider_envelope: [:0]const u8 = "";
    var j: i32 = 0;
    var count_j: i32 = 0;
    var field_id: [:0]const u8 = "";
    var show: [:0]const u8 = "";
    var required: [:0]const u8 = "";
    var value: [:0]const u8 = "";
    var configuration_type: [:0]const u8 = "";
    var error_details_error_code: [:0]const u8 = "";
    var error_details_message: [: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");
    _ = try j_resp.stringOf(alloc, "previousUri");
    _ = try j_resp.stringOf(alloc, "nextUri");
    var i: i32 = 0;
    const count_i = j_resp.sizeOfArray("folderItems");
    while (i < count_i) {
        j_resp.setI(i);
        owner_name = try j_resp.stringOf(alloc, "folderItems[i].ownerName");
        envelope_id = try j_resp.stringOf(alloc, "folderItems[i].envelopeId");
        envelope_uri = try j_resp.stringOf(alloc, "folderItems[i].envelopeUri");
        status = try j_resp.stringOf(alloc, "folderItems[i].status");
        sender_name = try j_resp.stringOf(alloc, "folderItems[i].senderName");
        sender_email = try j_resp.stringOf(alloc, "folderItems[i].senderEmail");
        created_date_time = try j_resp.stringOf(alloc, "folderItems[i].createdDateTime");
        sent_date_time = try j_resp.stringOf(alloc, "folderItems[i].sentDateTime");
        completed_date_time = try j_resp.stringOf(alloc, "folderItems[i].completedDateTime");
        subject = try j_resp.stringOf(alloc, "folderItems[i].subject");
        template_id = try j_resp.stringOf(alloc, "folderItems[i].templateId");
        name = try j_resp.stringOf(alloc, "folderItems[i].name");
        shared = try j_resp.stringOf(alloc, "folderItems[i].shared");
        password = try j_resp.stringOf(alloc, "folderItems[i].password");
        description = try j_resp.stringOf(alloc, "folderItems[i].description");
        last_modified = try j_resp.stringOf(alloc, "folderItems[i].lastModified");
        page_count = j_resp.intOf("folderItems[i].pageCount");
        uri = try j_resp.stringOf(alloc, "folderItems[i].uri");
        is21_cfr_part11 = try j_resp.stringOf(alloc, "folderItems[i].is21CFRPart11");
        is_signature_provider_envelope = try j_resp.stringOf(alloc, "folderItems[i].isSignatureProviderEnvelope");
        j = 0;
        count_j = j_resp.sizeOfArray("folderItems[i].customFields");
        while (j < count_j) {
            j_resp.setJ(j);
            field_id = try j_resp.stringOf(alloc, "folderItems[i].customFields[j].fieldId");
            name = try j_resp.stringOf(alloc, "folderItems[i].customFields[j].name");
            show = try j_resp.stringOf(alloc, "folderItems[i].customFields[j].show");
            required = try j_resp.stringOf(alloc, "folderItems[i].customFields[j].required");
            value = try j_resp.stringOf(alloc, "folderItems[i].customFields[j].value");
            configuration_type = try j_resp.stringOf(alloc, "folderItems[i].customFields[j].configurationType");
            error_details_error_code = try j_resp.stringOf(alloc, "folderItems[i].customFields[j].errorDetails.errorCode");
            error_details_message = try j_resp.stringOf(alloc, "folderItems[i].customFields[j].errorDetails.message");
            j = j + 1;
        }

        i = i + 1;
    }
}