Sample code for 30+ languages & platforms
Rust

DocuSign Download Envelope Document (PDF)

See more DocuSign Examples

Retrieves the specified document from the envelope. The response body of this method is the PDF file as a byte stream. You can get the file name and document ID from the response's Content-Disposition header.

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 HTTP request:
// GET /restapi/v2.1/accounts/{accountId}/envelopes/{envelopeId}/documents/1

// Adds the "Authorization: Bearer eyJ0eXAi.....UE8Kl_V8KroQ" header.
let json_token = chilkat::JsonObject::new();
// Load a previously obtained OAuth2 access token.
if json_token.load_file("qa_data/tokens/docusign.json").is_err() {
    println!("{}", json_token.last_error_text());
    return;
}

http.set_auth_token(&json_token.string_of("access_token").unwrap_or_default());

// Use your account ID and a valid envelopeId here:
let _ = http.set_url_var("accountId", "7f3f65ed-5e87-418d-94c1-92499ddc8252");
let _ = http.set_url_var("envelopeId", "90d7e40a-b4bd-4ccd-bf38-c80e37954a13");

let url = "https://demo.docusign.net/restapi/v2.1/accounts/{$accountId}/envelopes/{$envelopeId}/documents/1".to_string();
let bd = chilkat::BinData::new();

if http.download_bd(&url, &bd).is_err() {
    println!("{}", http.last_error_text());
    return;
}

let resp_status_code = http.last_status();
println!("Response Status Code = {}", resp_status_code);
if resp_status_code != 200 {
    println!("Response Header:");
    println!("{}", http.last_response_header());
    // The response body contains an error message.
    println!("{}", bd.get_string("utf-8").unwrap_or_default());
    println!("Failed.");
    return;
}

// The response indicated success.
// Get the filename from the Content-Disposition header and save to a file.
let mime = chilkat::Mime::new();
let _ = mime.load_mime(&http.last_response_header());

let filename = mime.get_header_field_attribute("Content-Disposition", "filename").unwrap_or_default();
println!("filename = {}", filename);

let sb_path = chilkat::StringBuilder::new();
let _ = sb_path.append("C:/aaworkarea/");
let _ = sb_path.append(&filename);
if bd.write_file(&sb_path.get_as_string().unwrap_or_default()).is_err() {
    println!("Failed to save to output file.");
} else {
    println!("Wrote {}", sb_path.get_as_string().unwrap_or_default());
}