Sample code for 30+ languages & platforms
Rust

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 Rust Downloads

Rust

// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

let http = chilkat::Http::new();

// 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"
//         }
//       ]
//     }
//   ]
// }

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

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

let resp = chilkat::HttpResponse::new();
if http.http_json("POST", "https://staging-api.yousign.com/procedures", &json, "application/json", &resp).is_err() {
    println!("{}", http.last_error_text());
    return;
}

let sb_response_body = chilkat::StringBuilder::new();
let _ = resp.get_body_sb(&sb_response_body);
let j_resp = chilkat::JsonObject::new();
let _ = j_resp.load_sb(&sb_response_body);
j_resp.set_emit_compact(false);

println!("Response Body:");
println!("{}", j_resp.emit().unwrap_or_default());

let resp_status_code = resp.status_code();
println!("Response Status Code = {}", resp_status_code);
if resp_status_code >= 400 {
    println!("Response Header:");
    println!("{}", resp.header());
    println!("Failed.");
    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

let mut j: i32 = 0;
let mut count_j: i32 = 0;
let mut k: i32 = 0;
let mut count_k: i32 = 0;

let mut id = j_resp.string_of("id").unwrap_or_default();
let mut name = j_resp.string_of("name").unwrap_or_default();
let mut description = j_resp.string_of("description").unwrap_or_default();
let mut created_at = j_resp.string_of("createdAt").unwrap_or_default();
let mut updated_at = j_resp.string_of("updatedAt").unwrap_or_default();
let mut finished_at = j_resp.string_of("finishedAt").unwrap_or_default();
let expires_at = j_resp.string_of("expiresAt").unwrap_or_default();
let mut status = j_resp.string_of("status").unwrap_or_default();
let mut creator = j_resp.string_of("creator").unwrap_or_default();
let creator_first_name = j_resp.string_of("creatorFirstName").unwrap_or_default();
let creator_last_name = j_resp.string_of("creatorLastName").unwrap_or_default();
let mut workspace = j_resp.string_of("workspace").unwrap_or_default();
let template = j_resp.bool_of("template");
let ordered = j_resp.bool_of("ordered");
let mut parent = j_resp.string_of("parent").unwrap_or_default();
let related_files_enable = j_resp.bool_of("relatedFilesEnable");
let archive = j_resp.bool_of("archive");
let mut i = 0;
let mut count_i = j_resp.size_of_array("metadata");
while i < count_i {
    j_resp.set_i(i);
    i = i + 1;
}

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

i = 0;
count_i = j_resp.size_of_array("members");
while i < count_i {
    j_resp.set_i(i);
    id = j_resp.string_of("members[i].id").unwrap_or_default();
    let _ = j_resp.string_of("members[i].user").unwrap_or_default();
    let _ = j_resp.string_of("members[i].type").unwrap_or_default();
    let _ = j_resp.string_of("members[i].firstname").unwrap_or_default();
    let _ = j_resp.string_of("members[i].lastname").unwrap_or_default();
    let _ = j_resp.string_of("members[i].email").unwrap_or_default();
    let _ = j_resp.string_of("members[i].phone").unwrap_or_default();
    let _ = j_resp.int_of("members[i].position");
    created_at = j_resp.string_of("members[i].createdAt").unwrap_or_default();
    updated_at = j_resp.string_of("members[i].updatedAt").unwrap_or_default();
    finished_at = j_resp.string_of("members[i].finishedAt").unwrap_or_default();
    status = j_resp.string_of("members[i].status").unwrap_or_default();
    let _ = j_resp.string_of("members[i].comment").unwrap_or_default();
    let _ = j_resp.string_of("members[i].operationLevel").unwrap_or_default();
    let _ = j_resp.string_of("members[i].operationModeSmsConfig").unwrap_or_default();
    parent = j_resp.string_of("members[i].parent").unwrap_or_default();
    j = 0;
    count_j = j_resp.size_of_array("members[i].fileObjects");
    while j < count_j {
        j_resp.set_j(j);
        id = j_resp.string_of("members[i].fileObjects[j].id").unwrap_or_default();
        let _ = j_resp.string_of("members[i].fileObjects[j].file.id").unwrap_or_default();
        let _ = j_resp.string_of("members[i].fileObjects[j].file.name").unwrap_or_default();
        let _ = j_resp.string_of("members[i].fileObjects[j].file.type").unwrap_or_default();
        let _ = j_resp.string_of("members[i].fileObjects[j].file.contentType").unwrap_or_default();
        let _ = j_resp.string_of("members[i].fileObjects[j].file.description").unwrap_or_default();
        let _ = j_resp.string_of("members[i].fileObjects[j].file.createdAt").unwrap_or_default();
        let _ = j_resp.string_of("members[i].fileObjects[j].file.updatedAt").unwrap_or_default();
        let _ = j_resp.string_of("members[i].fileObjects[j].file.sha256").unwrap_or_default();
        let _ = j_resp.string_of("members[i].fileObjects[j].file.workspace").unwrap_or_default();
        let _ = j_resp.string_of("members[i].fileObjects[j].file.creator").unwrap_or_default();
        let _ = j_resp.bool_of("members[i].fileObjects[j].file.protected");
        let _ = j_resp.int_of("members[i].fileObjects[j].file.position");
        let _ = j_resp.string_of("members[i].fileObjects[j].file.parent").unwrap_or_default();
        let _ = j_resp.int_of("members[i].fileObjects[j].page");
        let _ = j_resp.string_of("members[i].fileObjects[j].position").unwrap_or_default();
        let _ = j_resp.string_of("members[i].fileObjects[j].fieldName").unwrap_or_default();
        let _ = j_resp.string_of("members[i].fileObjects[j].mention").unwrap_or_default();
        let _ = j_resp.string_of("members[i].fileObjects[j].mention2").unwrap_or_default();
        created_at = j_resp.string_of("members[i].fileObjects[j].createdAt").unwrap_or_default();
        updated_at = j_resp.string_of("members[i].fileObjects[j].updatedAt").unwrap_or_default();
        parent = j_resp.string_of("members[i].fileObjects[j].parent").unwrap_or_default();
        let _ = j_resp.string_of("members[i].fileObjects[j].reason").unwrap_or_default();
        k = 0;
        count_k = j_resp.size_of_array("members[i].fileObjects[j].file.metadata");
        while k < count_k {
            j_resp.set_k(k);
            k = k + 1;
        }

        j = j + 1;
    }

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

    j = 0;
    count_j = j_resp.size_of_array("members[i].operationCustomModes");
    while j < count_j {
        j_resp.set_j(j);
        let _ = j_resp.string_of("members[i].operationCustomModes[j]").unwrap_or_default();
        j = j + 1;
    }

    i = i + 1;
}

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

i = 0;
count_i = j_resp.size_of_array("files");
while i < count_i {
    j_resp.set_i(i);
    id = j_resp.string_of("files[i].id").unwrap_or_default();
    name = j_resp.string_of("files[i].name").unwrap_or_default();
    let _ = j_resp.string_of("files[i].type").unwrap_or_default();
    let _ = j_resp.string_of("files[i].contentType").unwrap_or_default();
    description = j_resp.string_of("files[i].description").unwrap_or_default();
    created_at = j_resp.string_of("files[i].createdAt").unwrap_or_default();
    updated_at = j_resp.string_of("files[i].updatedAt").unwrap_or_default();
    let _ = j_resp.string_of("files[i].sha256").unwrap_or_default();
    workspace = j_resp.string_of("files[i].workspace").unwrap_or_default();
    creator = j_resp.string_of("files[i].creator").unwrap_or_default();
    let _ = j_resp.bool_of("files[i].protected");
    let _ = j_resp.int_of("files[i].position");
    parent = j_resp.string_of("files[i].parent").unwrap_or_default();
    j = 0;
    count_j = j_resp.size_of_array("files[i].metadata");
    while j < count_j {
        j_resp.set_j(j);
        j = j + 1;
    }

    i = i + 1;
}

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

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

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