Sample code for 30+ languages & platforms
Zig

DocuSign List Envelope Documents

See more DocuSign Examples

Retrieve a list of all documents within a specific envelope.

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}/envelopes/{envelopeId}/documents

    // 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 envelopeId here:
    http.setUrlVar("accountId", "7f3f65ed-5e87-418d-94c1-92499ddc8252") catch {};
    http.setUrlVar("envelopeId", "90d7e40a-b4bd-4ccd-bf38-c80e37954a13") 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}/envelopes/{$envelopeId}/documents", 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)

    // {
    //   "envelopeId": "90d7e40a-b4bd-4ccd-bf38-c80e37954a13",
    //   "envelopeDocuments": [
    //     {
    //       "documentId": "1",
    //       "documentIdGuid": "ca1d3cc6-9bc3-48d6-a5d8-a85d9acdcde1",
    //       "name": "helloWorld.pdf",
    //       "type": "content",
    //       "uri": "/envelopes/90d7e40a-b4bd-4ccd-bf38-c80e37954a13/documents/1",
    //       "order": "1",
    //       "pages": [
    //         {
    //           "pageId": "fbf93a36-6b60-484d-94bd-ee3c08c0a546",
    //           "sequence": "1",
    //           "height": "842",
    //           "width": "595",
    //           "dpi": "72"
    //         }
    //       ],
    //       "availableDocumentTypes": [
    //         {
    //           "type": "electronic",
    //           "isDefault": "true"
    //         }
    //       ],
    //       "display": "inline",
    //       "includeInDownload": "true",
    //       "signerMustAcknowledge": "no_interaction",
    //       "templateRequired": "false",
    //       "authoritativeCopy": "false"
    //     },
    //     {
    //       "documentId": "certificate",
    //       "documentIdGuid": "7479a5de-8d91-44a2-bc33-b76a9ba0f6e2",
    //       "name": "Summary",
    //       "type": "summary",
    //       "uri": "/envelopes/90d7e40a-b4bd-4ccd-bf38-c80e37954a13/documents/certificate",
    //       "order": "999",
    //       "availableDocumentTypes": [
    //         {
    //           "type": "electronic",
    //           "isDefault": "true"
    //         }
    //       ],
    //       "display": "inline",
    //       "includeInDownload": "true",
    //       "signerMustAcknowledge": "no_interaction",
    //       "templateRequired": "false",
    //       "authoritativeCopy": "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 document_id: [:0]const u8 = "";
    var document_id_guid: [:0]const u8 = "";
    var name: [:0]const u8 = "";
    var v_type: [:0]const u8 = "";
    var uri: [:0]const u8 = "";
    var order: [:0]const u8 = "";
    var display: [:0]const u8 = "";
    var include_in_download: [:0]const u8 = "";
    var signer_must_acknowledge: [:0]const u8 = "";
    var template_required: [:0]const u8 = "";
    var authoritative_copy: [:0]const u8 = "";
    var j: i32 = 0;
    var count_j: i32 = 0;
    var page_id: [:0]const u8 = "";
    var sequence: [:0]const u8 = "";
    var height: [:0]const u8 = "";
    var width: [:0]const u8 = "";
    var dpi: [:0]const u8 = "";
    var is_default: [:0]const u8 = "";

    _ = try j_resp.stringOf(alloc, "envelopeId");
    var i: i32 = 0;
    const count_i = j_resp.sizeOfArray("envelopeDocuments");
    while (i < count_i) {
        j_resp.setI(i);
        document_id = try j_resp.stringOf(alloc, "envelopeDocuments[i].documentId");
        document_id_guid = try j_resp.stringOf(alloc, "envelopeDocuments[i].documentIdGuid");
        name = try j_resp.stringOf(alloc, "envelopeDocuments[i].name");
        v_type = try j_resp.stringOf(alloc, "envelopeDocuments[i].type");
        uri = try j_resp.stringOf(alloc, "envelopeDocuments[i].uri");
        order = try j_resp.stringOf(alloc, "envelopeDocuments[i].order");
        display = try j_resp.stringOf(alloc, "envelopeDocuments[i].display");
        include_in_download = try j_resp.stringOf(alloc, "envelopeDocuments[i].includeInDownload");
        signer_must_acknowledge = try j_resp.stringOf(alloc, "envelopeDocuments[i].signerMustAcknowledge");
        template_required = try j_resp.stringOf(alloc, "envelopeDocuments[i].templateRequired");
        authoritative_copy = try j_resp.stringOf(alloc, "envelopeDocuments[i].authoritativeCopy");
        j = 0;
        count_j = j_resp.sizeOfArray("envelopeDocuments[i].pages");
        while (j < count_j) {
            j_resp.setJ(j);
            page_id = try j_resp.stringOf(alloc, "envelopeDocuments[i].pages[j].pageId");
            sequence = try j_resp.stringOf(alloc, "envelopeDocuments[i].pages[j].sequence");
            height = try j_resp.stringOf(alloc, "envelopeDocuments[i].pages[j].height");
            width = try j_resp.stringOf(alloc, "envelopeDocuments[i].pages[j].width");
            dpi = try j_resp.stringOf(alloc, "envelopeDocuments[i].pages[j].dpi");
            j = j + 1;
        }

        j = 0;
        count_j = j_resp.sizeOfArray("envelopeDocuments[i].availableDocumentTypes");
        while (j < count_j) {
            j_resp.setJ(j);
            v_type = try j_resp.stringOf(alloc, "envelopeDocuments[i].availableDocumentTypes[j].type");
            is_default = try j_resp.stringOf(alloc, "envelopeDocuments[i].availableDocumentTypes[j].isDefault");
            j = j + 1;
        }

        i = i + 1;
    }
}