Sample code for 30+ languages & platforms
Rust

Yousign Procedure Creation Basic Mode Upload File

See more Yousign Examples

Demonstrates the 1st step of Yousign procedure creation, which is to upload a 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/files' \
// --header 'Authorization: Bearer YOUR_API_KEY' \
// --header 'Content-Type: application/json' \
// --data-raw '{
//     "name": "The best name for my file.pdf",
//     "content": "JVBERi0..." }'

// Load a PDF file to be uploaded.
let pdf_data = chilkat::BinData::new();
if pdf_data.load_file("qa_data/pdf/helloWorld.pdf").is_err() {
    println!("Failed to load PDF local file.");
    return;
}

// 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": "The best name for my file.pdf",
//   "content": "JVBERi0..."
// }

let json = chilkat::JsonObject::new();
let _ = json.update_string("name", "helloWorld.pdf");
let _ = json.update_string("content", &pdf_data.get_encoded("base64").unwrap_or_default());

// 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/files", &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": "/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:36:20+01:00",
//   "sha256": "bb57ae2b2ca6ad0133a699350d1a6f6c8cdfde3cf872cf526585d306e4675cc2",
//   "metadata": [
//   ],
//   "workspace": "/workspaces/XXXXXX-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

let id = j_resp.string_of("id").unwrap_or_default();
let name = j_resp.string_of("name").unwrap_or_default();
let v_type = j_resp.string_of("type").unwrap_or_default();
let content_type = j_resp.string_of("contentType").unwrap_or_default();
let description = j_resp.string_of("description").unwrap_or_default();
let created_at = j_resp.string_of("createdAt").unwrap_or_default();
let updated_at = j_resp.string_of("updatedAt").unwrap_or_default();
let sha256 = j_resp.string_of("sha256").unwrap_or_default();
let workspace = j_resp.string_of("workspace").unwrap_or_default();
let creator = j_resp.string_of("creator").unwrap_or_default();
let v_protected = j_resp.bool_of("protected");
let position = j_resp.int_of("position");
let parent = j_resp.string_of("parent").unwrap_or_default();
let mut i = 0;
let count_i = j_resp.size_of_array("metadata");
while i < count_i {
    j_resp.set_i(i);
    i = i + 1;
}