Sample code for 30+ languages & platforms
Rust

Retrieve User Account Data

See more DocuSign Examples

To make an API call to the DocuSign platform, your application needs both an access token (which you obtained in the previous step), and base URI that is unique to the user on whose behalf your application is making the API call. To get the base URI, call the/oauth/userinfoendpoint, supplying your application’s access token as a 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 CURL command:

// curl --header "Authorization: Bearer eyJ0eXAi.....UE8Kl_V8KroQ" https://account-d.docusign.com/oauth/userinfo

// 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 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());

let sb_response_body = chilkat::StringBuilder::new();
if http.quick_get_sb("https://account-d.docusign.com/oauth/userinfo", &sb_response_body).is_err() {
    println!("{}", http.last_error_text());
    return;
}

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 = http.last_status();
println!("Response Status Code = {}", resp_status_code);
if resp_status_code >= 400 {
    println!("Response Header:");
    println!("{}", http.last_response_header());
    println!("Failed.");
    return;
}

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

// {
//   "sub": "564f7988-xxxx-xxxx-xxxx-781ee556ab7a",
//   "name": "Example J Smith",
//   "given_name": "Example",
//   "family_name": "Smith",
//   "created": "2018-04-13T22:03:03.45",
//   "email": "Example.Smith@exampledomain.com",
//   "accounts": [
//     {
//       "account_id": "18b4799a-xxxx-xxxx-xxxx-b5b4b8a97604",
//       "is_default": true,
//       "account_name": "ExampleAccount",
//       "base_uri": "https://demo.docusign.net"
//     }
//   ]
// }

// 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 sub = j_resp.string_of("sub").unwrap_or_default();
let name = j_resp.string_of("name").unwrap_or_default();
let given_name = j_resp.string_of("given_name").unwrap_or_default();
let family_name = j_resp.string_of("family_name").unwrap_or_default();
let created = j_resp.string_of("created").unwrap_or_default();
let email = j_resp.string_of("email").unwrap_or_default();
let mut i = 0;
let count_i = j_resp.size_of_array("accounts");
while i < count_i {
    j_resp.set_i(i);
    let _ = j_resp.string_of("accounts[i].account_id").unwrap_or_default();
    let _ = j_resp.bool_of("accounts[i].is_default");
    let _ = j_resp.string_of("accounts[i].account_name").unwrap_or_default();
    let _ = j_resp.string_of("accounts[i].base_uri").unwrap_or_default();
    i = i + 1;
}