Sample code for 30+ languages & platforms
Zig

Yousign Create Procedure after Uploading the PDF

See more Yousign Examples

Demonstrates the 2nd step of Yousign procedure creation. This is the call to create the procedure after previously uploading the PDF file.

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 POST 'https://staging-api.yousign.com/procedures' \
    // --header 'Authorization: Bearer YOUR_API_KEY' \
    // --header 'Content-Type: application/json' \
    // --data-raw '{
    //     "name": "My first procedure",
    //     "description": "Awesome! Here is the description of my first procedure",
    //     "members": [
    //         {
    //             "firstname": "John",
    //             "lastname": "Doe",
    //             "email": "john.doe@yousign.fr",
    //             "phone": "+33612345678",
    //             "fileObjects": [
    //                 {
    //                     "file": "/files/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
    //                     "page": 2,
    //                     "position": "230,499,464,589",
    //                     "mention": "Read and approved",
    //                     "mention2": "Signed by John Doe"
    //                 }
    //             ]
    //         }
    //     ]
    // }'

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

    // Use this online tool to generate code from sample JSON:
    // Generate Code to Create JSON

    // The following JSON is sent in the request body.

    // {
    //   "name": "My first procedure",
    //   "description": "Awesome! Here is the description of my first procedure",
    //   "members": [
    //     {
    //       "firstname": "John",
    //       "lastname": "Doe",
    //       "email": "john.doe@yousign.fr",
    //       "phone": "+33612345678",
    //       "fileObjects": [
    //         {
    //           "file": "/files/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
    //           "page": 2,
    //           "position": "230,499,464,589",
    //           "mention": "Read and approved",
    //           "mention2": "Signed by John Doe"
    //         }
    //       ]
    //     }
    //   ]
    // }

    const json = try chilkat.JsonObject.init();
    defer json.deinit();
    json.updateString("name", "My first procedure") catch {};
    json.updateString("description", "Awesome! Here is the description of my first procedure") catch {};
    json.updateString("members[0].firstname", "John") catch {};
    json.updateString("members[0].lastname", "Doe") catch {};
    json.updateString("members[0].email", "john.doe@yousign.fr") catch {};
    json.updateString("members[0].phone", "+33612345678") catch {};
    json.updateString("members[0].fileObjects[0].file", "/files/6c123a8d-e5cf-4534-8da0-81886376ba2c") catch {};
    json.updateInt("members[0].fileObjects[0].page", 2) catch {};
    json.updateString("members[0].fileObjects[0].position", "230,499,464,589") catch {};
    json.updateString("members[0].fileObjects[0].mention", "Read and approved") catch {};
    json.updateString("members[0].fileObjects[0].mention2", "Signed by John Doe") catch {};

    // Adds the "Authorization: Bearer YOUR_API_KEY" header.
    http.setAuthToken("YOUR_API_KEY");

    const resp = try chilkat.HttpResponse.init();
    defer resp.deinit();
    http.httpJson("POST", "https://staging-api.yousign.com/procedures", json, "application/json", resp) catch {
        std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
        return;
    };

    const sb_response_body = try chilkat.StringBuilder.init();
    defer sb_response_body.deinit();
    resp.getBodySb(sb_response_body) catch {};
    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 = resp.getStatusCode();
    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 resp.getHeader(alloc)});
        std.debug.print("Failed.\n", .{});
        return;
    }

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

    // {
    //   "id": "/procedures/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
    //   "name": "My first procedure",
    //   "description": "Awesome! Here is the description of my first procedure",
    //   "createdAt": "2018-12-01T11:49:11+01:00",
    //   "updatedAt": "2018-12-01T11:49:11+01:00",
    //   "finishedAt": null,
    //   "expiresAt": null,
    //   "status": "active",
    //   "creator": null,
    //   "creatorFirstName": null,
    //   "creatorLastName": null,
    //   "workspace": "/workspaces/XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
    //   "template": false,
    //   "ordered": false,
    //   "parent": null,
    //   "metadata": [
    //   ],
    //   "config": [
    //   ],
    //   "members": [
    //     {
    //       "id": "/members/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
    //       "user": null,
    //       "type": "signer",
    //       "firstname": "John",
    //       "lastname": "Doe",
    //       "email": "john.doe@yousign.fr",
    //       "phone": "+33612345678",
    //       "position": 1,
    //       "createdAt": "2018-12-01T11:49:11+01:00",
    //       "updatedAt": "2018-12-01T11:49:11+01:00",
    //       "finishedAt": null,
    //       "status": "pending",
    //       "fileObjects": [
    //         {
    //           "id": "/file_objects/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
    //           "file": {
    //             "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-01T11:36:20+01:00",
    //             "updatedAt": "2018-12-01T11:49:11+01:00",
    //             "sha256": "bb57ae2b2ca6ad0133a699350d1a6f6c8cdfde3cf872cf526585d306e4675cc2",
    //             "metadata": [
    //             ],
    //             "workspace": "/workspaces/XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
    //             "creator": null,
    //             "protected": false,
    //             "position": 0,
    //             "parent": null
    //           },
    //           "page": 2,
    //           "position": "230,499,464,589",
    //           "fieldName": null,
    //           "mention": "Read and approved",
    //           "mention2": "Signed by John Doe",
    //           "createdAt": "2018-12-01T11:49:11+01:00",
    //           "updatedAt": "2018-12-01T11:49:11+01:00",
    //           "parent": null,
    //           "reason": "Signed by Yousign"
    //         }
    //       ],
    //       "comment": null,
    //       "notificationsEmail": [
    //       ],
    //       "operationLevel": "custom",
    //       "operationCustomModes": [
    //         "sms"
    //       ],
    //       "operationModeSmsConfig": null,
    //       "parent": null
    //     }
    //   ],
    //   "subscribers": [
    //   ],
    //   "files": [
    //     {
    //       "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-01T11:36:20+01:00",
    //       "updatedAt": "2018-12-01T11:49:11+01:00",
    //       "sha256": "bb57ae2b2ca6ad0133a699350d1a6f6c8cdfde3cf872cf526585d306e4675cc2",
    //       "metadata": [
    //       ],
    //       "workspace": "/workspaces/XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
    //       "creator": null,
    //       "protected": false,
    //       "position": 0,
    //       "parent": null
    //     }
    //   ],
    //   "relatedFilesEnable": false,
    //   "archive": false,
    //   "archiveMetadata": [
    //   ],
    //   "fields": [
    //   ],
    //   "permissions": [
    //   ]
    // }

    // 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 user: [:0]const u8 = "";
    var v_type: [:0]const u8 = "";
    var firstname: [:0]const u8 = "";
    var lastname: [:0]const u8 = "";
    var email: [:0]const u8 = "";
    var phone: [:0]const u8 = "";
    var position: i32 = 0;
    var comment: [:0]const u8 = "";
    var operation_level: [:0]const u8 = "";
    var operation_mode_sms_config: [:0]const u8 = "";
    var j: i32 = 0;
    var count_j: i32 = 0;
    var file_id: [:0]const u8 = "";
    var file_name: [:0]const u8 = "";
    var file_type: [:0]const u8 = "";
    var file_content_type: [:0]const u8 = "";
    var file_description: [:0]const u8 = "";
    var file_created_at: [:0]const u8 = "";
    var file_updated_at: [:0]const u8 = "";
    var file_sha256: [:0]const u8 = "";
    var file_workspace: [:0]const u8 = "";
    var file_creator: [:0]const u8 = "";
    var file_protected: bool = false;
    var file_position: i32 = 0;
    var file_parent: [:0]const u8 = "";
    var page: i32 = 0;
    var position_str: [:0]const u8 = "";
    var field_name: [:0]const u8 = "";
    var mention: [:0]const u8 = "";
    var mention2: [:0]const u8 = "";
    var reason: [:0]const u8 = "";
    var k: i32 = 0;
    var count_k: i32 = 0;
    var str_val: [:0]const u8 = "";
    var content_type: [:0]const u8 = "";
    var sha256: [:0]const u8 = "";
    var v_protected: bool = false;

    var id: [:0]const u8 = try j_resp.stringOf(alloc, "id");
    var name: [:0]const u8 = try j_resp.stringOf(alloc, "name");
    var description: [:0]const u8 = try j_resp.stringOf(alloc, "description");
    var created_at: [:0]const u8 = try j_resp.stringOf(alloc, "createdAt");
    var updated_at: [:0]const u8 = try j_resp.stringOf(alloc, "updatedAt");
    var finished_at: [:0]const u8 = try j_resp.stringOf(alloc, "finishedAt");
    _ = try j_resp.stringOf(alloc, "expiresAt");
    var status: [:0]const u8 = try j_resp.stringOf(alloc, "status");
    var creator: [:0]const u8 = try j_resp.stringOf(alloc, "creator");
    _ = try j_resp.stringOf(alloc, "creatorFirstName");
    _ = try j_resp.stringOf(alloc, "creatorLastName");
    var workspace: [:0]const u8 = try j_resp.stringOf(alloc, "workspace");
    _ = j_resp.boolOf("template");
    _ = j_resp.boolOf("ordered");
    var parent: [:0]const u8 = try j_resp.stringOf(alloc, "parent");
    _ = j_resp.boolOf("relatedFilesEnable");
    _ = j_resp.boolOf("archive");
    var i: i32 = 0;
    var count_i: i32 = j_resp.sizeOfArray("metadata");
    while (i < count_i) {
        j_resp.setI(i);
        i = i + 1;
    }

    i = 0;
    count_i = j_resp.sizeOfArray("config");
    while (i < count_i) {
        j_resp.setI(i);
        i = i + 1;
    }

    i = 0;
    count_i = j_resp.sizeOfArray("members");
    while (i < count_i) {
        j_resp.setI(i);
        id = try j_resp.stringOf(alloc, "members[i].id");
        user = try j_resp.stringOf(alloc, "members[i].user");
        v_type = try j_resp.stringOf(alloc, "members[i].type");
        firstname = try j_resp.stringOf(alloc, "members[i].firstname");
        lastname = try j_resp.stringOf(alloc, "members[i].lastname");
        email = try j_resp.stringOf(alloc, "members[i].email");
        phone = try j_resp.stringOf(alloc, "members[i].phone");
        position = j_resp.intOf("members[i].position");
        created_at = try j_resp.stringOf(alloc, "members[i].createdAt");
        updated_at = try j_resp.stringOf(alloc, "members[i].updatedAt");
        finished_at = try j_resp.stringOf(alloc, "members[i].finishedAt");
        status = try j_resp.stringOf(alloc, "members[i].status");
        comment = try j_resp.stringOf(alloc, "members[i].comment");
        operation_level = try j_resp.stringOf(alloc, "members[i].operationLevel");
        operation_mode_sms_config = try j_resp.stringOf(alloc, "members[i].operationModeSmsConfig");
        parent = try j_resp.stringOf(alloc, "members[i].parent");
        j = 0;
        count_j = j_resp.sizeOfArray("members[i].fileObjects");
        while (j < count_j) {
            j_resp.setJ(j);
            id = try j_resp.stringOf(alloc, "members[i].fileObjects[j].id");
            file_id = try j_resp.stringOf(alloc, "members[i].fileObjects[j].file.id");
            file_name = try j_resp.stringOf(alloc, "members[i].fileObjects[j].file.name");
            file_type = try j_resp.stringOf(alloc, "members[i].fileObjects[j].file.type");
            file_content_type = try j_resp.stringOf(alloc, "members[i].fileObjects[j].file.contentType");
            file_description = try j_resp.stringOf(alloc, "members[i].fileObjects[j].file.description");
            file_created_at = try j_resp.stringOf(alloc, "members[i].fileObjects[j].file.createdAt");
            file_updated_at = try j_resp.stringOf(alloc, "members[i].fileObjects[j].file.updatedAt");
            file_sha256 = try j_resp.stringOf(alloc, "members[i].fileObjects[j].file.sha256");
            file_workspace = try j_resp.stringOf(alloc, "members[i].fileObjects[j].file.workspace");
            file_creator = try j_resp.stringOf(alloc, "members[i].fileObjects[j].file.creator");
            file_protected = j_resp.boolOf("members[i].fileObjects[j].file.protected");
            file_position = j_resp.intOf("members[i].fileObjects[j].file.position");
            file_parent = try j_resp.stringOf(alloc, "members[i].fileObjects[j].file.parent");
            page = j_resp.intOf("members[i].fileObjects[j].page");
            position_str = try j_resp.stringOf(alloc, "members[i].fileObjects[j].position");
            field_name = try j_resp.stringOf(alloc, "members[i].fileObjects[j].fieldName");
            mention = try j_resp.stringOf(alloc, "members[i].fileObjects[j].mention");
            mention2 = try j_resp.stringOf(alloc, "members[i].fileObjects[j].mention2");
            created_at = try j_resp.stringOf(alloc, "members[i].fileObjects[j].createdAt");
            updated_at = try j_resp.stringOf(alloc, "members[i].fileObjects[j].updatedAt");
            parent = try j_resp.stringOf(alloc, "members[i].fileObjects[j].parent");
            reason = try j_resp.stringOf(alloc, "members[i].fileObjects[j].reason");
            k = 0;
            count_k = j_resp.sizeOfArray("members[i].fileObjects[j].file.metadata");
            while (k < count_k) {
                j_resp.setK(k);
                k = k + 1;
            }

            j = j + 1;
        }

        j = 0;
        count_j = j_resp.sizeOfArray("members[i].notificationsEmail");
        while (j < count_j) {
            j_resp.setJ(j);
            j = j + 1;
        }

        j = 0;
        count_j = j_resp.sizeOfArray("members[i].operationCustomModes");
        while (j < count_j) {
            j_resp.setJ(j);
            str_val = try j_resp.stringOf(alloc, "members[i].operationCustomModes[j]");
            j = j + 1;
        }

        i = i + 1;
    }

    i = 0;
    count_i = j_resp.sizeOfArray("subscribers");
    while (i < count_i) {
        j_resp.setI(i);
        i = i + 1;
    }

    i = 0;
    count_i = j_resp.sizeOfArray("files");
    while (i < count_i) {
        j_resp.setI(i);
        id = try j_resp.stringOf(alloc, "files[i].id");
        name = try j_resp.stringOf(alloc, "files[i].name");
        v_type = try j_resp.stringOf(alloc, "files[i].type");
        content_type = try j_resp.stringOf(alloc, "files[i].contentType");
        description = try j_resp.stringOf(alloc, "files[i].description");
        created_at = try j_resp.stringOf(alloc, "files[i].createdAt");
        updated_at = try j_resp.stringOf(alloc, "files[i].updatedAt");
        sha256 = try j_resp.stringOf(alloc, "files[i].sha256");
        workspace = try j_resp.stringOf(alloc, "files[i].workspace");
        creator = try j_resp.stringOf(alloc, "files[i].creator");
        v_protected = j_resp.boolOf("files[i].protected");
        position = j_resp.intOf("files[i].position");
        parent = try j_resp.stringOf(alloc, "files[i].parent");
        j = 0;
        count_j = j_resp.sizeOfArray("files[i].metadata");
        while (j < count_j) {
            j_resp.setJ(j);
            j = j + 1;
        }

        i = i + 1;
    }

    i = 0;
    count_i = j_resp.sizeOfArray("archiveMetadata");
    while (i < count_i) {
        j_resp.setI(i);
        i = i + 1;
    }

    i = 0;
    count_i = j_resp.sizeOfArray("fields");
    while (i < count_i) {
        j_resp.setI(i);
        i = i + 1;
    }

    i = 0;
    count_i = j_resp.sizeOfArray("permissions");
    while (i < count_i) {
        j_resp.setI(i);
        i = i + 1;
    }
}