Sample code for 30+ languages & platforms
Zig

Yousign: Download Information about Previously Uploaded File

See more Yousign Examples

Demonstrates how to download the information (in JSON format) about a file previously uploaded.

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 CURL command:

    // curl --location --request GET 'https://staging-api.yousign.com/files/{{id}}' \
    // --header 'Authorization: Bearer YOUR_API_KEY' \
    // --header 'Content-Type: application/json'

    // Use the following online tool to generate HTTP code from a CURL command
    // Convert a cURL Command to HTTP Source Code

    // Adds the "Authorization: Bearer YOUR_API_KEY" header.
    http.setAuthToken("YOUR_API_KEY");
    http.setRequestHeader("Content-Type", "application/json");

    const sb_response_body = try chilkat.StringBuilder.init();
    defer sb_response_body.deinit();
    http.quickGetSb("https://staging-api.yousign.com/files/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX", 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)

    // {
    //   "id": "/files/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
    //   "name": "The best name for my file.pdf",
    //   "type": "signable",
    //   "contentType": "application/pdf",
    //   "description": null,
    //   "createdAt": "2018-12-07T08:10:21+01:00",
    //   "updatedAt": "2018-12-07T08:10:21+01:00",
    //   "sha256": "bb57ae2b2ca6ad0133a699350d1a6f6c8cdfde3cf872cf526585d306e4675cc2",
    //   "metadata": [
    //   ],
    //   "workspace": "/workspaces/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
    //   "creator": null,
    //   "protected": false,
    //   "position": 0,
    //   "parent": null
    // }

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

    _ = try j_resp.stringOf(alloc, "id");
    _ = try j_resp.stringOf(alloc, "name");
    _ = try j_resp.stringOf(alloc, "type");
    _ = try j_resp.stringOf(alloc, "contentType");
    _ = try j_resp.stringOf(alloc, "description");
    _ = try j_resp.stringOf(alloc, "createdAt");
    _ = try j_resp.stringOf(alloc, "updatedAt");
    _ = try j_resp.stringOf(alloc, "sha256");
    _ = try j_resp.stringOf(alloc, "workspace");
    _ = try j_resp.stringOf(alloc, "creator");
    _ = j_resp.boolOf("protected");
    _ = j_resp.intOf("position");
    _ = try j_resp.stringOf(alloc, "parent");
    var i: i32 = 0;
    const count_i = j_resp.sizeOfArray("metadata");
    while (i < count_i) {
        j_resp.setI(i);
        i = i + 1;
    }
}