Zig
Zig
Yousign: List Files
See more Yousign Examples
List Yousign files.Chilkat Zig Downloads
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' \
// --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", sb_response_body) catch {
std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
return;
};
const json = try chilkat.JsonObject.init();
defer json.deinit();
json.loadSb(sb_response_body) catch {};
json.setEmitCompact(false);
std.debug.print("Response Body:\n", .{});
std.debug.print("{s}\n", .{try json.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": "abc.pdf",
// "type": "signable",
// "contentType": "application\/pdf",
// "description": null,
// "createdAt": "2020-05-27T09:14:12+02:00",
// "updatedAt": "2020-05-27T09:14:12+02:00",
// "sha256": "ea2a92b0eff5bebfa3ccd869fd61e27bb7fe973d0dff63f106d8b0d614469fa0",
// "metadata": [
// ],
// "workspace": "\/workspaces\/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
// "creator": null,
// "fileObjects": [
// ],
// "protected": false,
// "position": 0,
// "parent": null,
// "fieldsCompatible": true,
// "company": "\/companies\/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
// }
// Use the following online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
_ = try json.stringOf(alloc, "id");
_ = try json.stringOf(alloc, "name");
_ = try json.stringOf(alloc, "type");
_ = try json.stringOf(alloc, "contentType");
_ = try json.stringOf(alloc, "description");
_ = try json.stringOf(alloc, "createdAt");
_ = try json.stringOf(alloc, "updatedAt");
_ = try json.stringOf(alloc, "sha256");
_ = try json.stringOf(alloc, "workspace");
_ = try json.stringOf(alloc, "creator");
_ = json.boolOf("protected");
_ = json.intOf("position");
_ = try json.stringOf(alloc, "parent");
_ = json.boolOf("fieldsCompatible");
_ = try json.stringOf(alloc, "company");
var i: i32 = 0;
var count_i: i32 = json.sizeOfArray("metadata");
while (i < count_i) {
json.setI(i);
i = i + 1;
}
i = 0;
count_i = json.sizeOfArray("fileObjects");
while (i < count_i) {
json.setI(i);
i = i + 1;
}
}