Zig
Zig
Yousign: Making your first API call
See more Yousign Examples
Demonstrates making the simplest of calls to test your API key. This example tests using the sandbox URLs.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/users' \
// --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/users", 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": "/users/XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
// "firstname": "John",
// "lastname": "Doe",
// "email": "john.doe@yousign.fr",
// "title": "Developer",
// "phone": "+33612345678",
// "status": "activated",
// "organization": "/organizations/XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
// "workspaces": [
// {
// "id": "/workspaces/XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
// "name": "Acme"
// }
// ],
// "permission": "ROLE_ADMIN",
// "group": {
// "id": "/user_groups/XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
// "name": "Administrateur",
// "permissions": [
// "procedure_write",
// "procedure_template_write",
// "procedure_create_from_template",
// "contact",
// "sign",
// "organization",
// "user",
// "api_key",
// "procedure_custom_field",
// "signature_ui",
// "certificate",
// "archive"
// ]
// },
// "createdAt": "2018-12-01T09:42:25+01:00",
// "updatedAt": "2018-12-01T09:42:25+01:00",
// "deleted": false,
// "deletedAt": null,
// "config": [
// ],
// "inweboUserRequest": null,
// "samlNameId": null,
// "defaultSignImage": null,
// "notifications": {
// "procedure": true
// },
// "fastSign": false,
// "fullName": "John Doe"
// }
// 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 str_val: [:0]const u8 = "";
var id: [:0]const u8 = try j_resp.stringOf(alloc, "id");
_ = try j_resp.stringOf(alloc, "firstname");
_ = try j_resp.stringOf(alloc, "lastname");
_ = try j_resp.stringOf(alloc, "email");
_ = try j_resp.stringOf(alloc, "title");
_ = try j_resp.stringOf(alloc, "phone");
_ = try j_resp.stringOf(alloc, "status");
_ = try j_resp.stringOf(alloc, "organization");
_ = try j_resp.stringOf(alloc, "permission");
_ = try j_resp.stringOf(alloc, "group.id");
_ = try j_resp.stringOf(alloc, "group.name");
_ = try j_resp.stringOf(alloc, "createdAt");
_ = try j_resp.stringOf(alloc, "updatedAt");
_ = j_resp.boolOf("deleted");
_ = try j_resp.stringOf(alloc, "deletedAt");
_ = try j_resp.stringOf(alloc, "inweboUserRequest");
_ = try j_resp.stringOf(alloc, "samlNameId");
_ = try j_resp.stringOf(alloc, "defaultSignImage");
_ = j_resp.boolOf("notifications.procedure");
_ = j_resp.boolOf("fastSign");
_ = try j_resp.stringOf(alloc, "fullName");
var i: i32 = 0;
var count_i: i32 = j_resp.sizeOfArray("workspaces");
while (i < count_i) {
j_resp.setI(i);
id = try j_resp.stringOf(alloc, "workspaces[i].id");
name = try j_resp.stringOf(alloc, "workspaces[i].name");
i = i + 1;
}
i = 0;
count_i = j_resp.sizeOfArray("group.permissions");
while (i < count_i) {
j_resp.setI(i);
str_val = try j_resp.stringOf(alloc, "group.permissions[i]");
i = i + 1;
}
i = 0;
count_i = j_resp.sizeOfArray("config");
while (i < count_i) {
j_resp.setI(i);
i = i + 1;
}
}