Sample code for 30+ languages & platforms
Rust

Docusign: Return Brand Data Associated with a User

See more DocuSign Examples

Demonstrates a call using an OAuth2 access token in combination with the account ID for which we have authorization.

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 --request GET https://account-d.docusign.com/restapi/v2/accounts/18b4799a-xxxx-xxxx-xxxx-b5b4b8a97604/brands --header "Authorization: Bearer eyJ0eXAi.....UE8Kl_V8KroQ"

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

// Use an account ID obtained from DocuSign Get User Account Data
let sb_response_body = chilkat::StringBuilder::new();
if http.quick_get_sb("https://account-d.docusign.com/restapi/v2/accounts/18b4799a-xxxx-xxxx-xxxx-b5b4b8a97604/brands", &sb_response_body).is_err() {
    println!("{}", http.last_error_text());
    return;
}

let json = chilkat::JsonObject::new();
let _ = json.load_sb(&sb_response_body);
json.set_emit_compact(false);

println!("Response Body:");
println!("{}", json.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_header());
    println!("Failed.");
    return;
}

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

// {
//   "recipientBrandIdDefault": "sample string 1",
//   "senderBrandIdDefault": "sample string 2",
//   "brands": [
//     {
//       "brandCompany": "sample string 1",
//       "brandId": "sample string 2",
//       "brandName": "sample string 3",
//       "colors": [
//         {}
//       ],
//       "errorDetails": {
//         "errorCode": "sample string 1",
//         "message": "sample string 2"
//       },
//       "isOverridingCompanyName": "sample string 4",
//       "isSendingDefault": "sample string 5",
//       "isSigningDefault": "sample string 6",
//       "landingPages": [
//         {}
//       ],
//       "links": [
//         {
//           "linkType": "sample string 1",
//           "urlOrMailTo": "sample string 2",
//           "linkText": "sample string 3",
//           "showLink": "sample string 4"
//         }
//       ],
//       "emailContent": [
//         {
//           "emailContentType": "sample string 1",
//           "content": "sample string 2",
//           "emailToLink": "sample string 3",
//           "linkText": "sample string 4"
//         }
//       ],
//       "logos": {
//         "primary": "sample string 1",
//         "secondary": "sample string 2",
//         "email": "sample string 3"
//       },
//       "resources": {
//         "email": "sample string 1",
//         "sending": "sample string 2",
//         "signing": "sample string 3",
//         "signingCaptive": "sample string 4"
//       }
//     }
//   ]
// }

// 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 recipient_brand_id_default = json.string_of("recipientBrandIdDefault").unwrap_or_default();
let sender_brand_id_default = json.string_of("senderBrandIdDefault").unwrap_or_default();
let mut i = 0;
let count_i = json.size_of_array("brands");
while i < count_i {
    json.set_i(i);
    let _ = json.string_of("brands[i].brandCompany").unwrap_or_default();
    let _ = json.string_of("brands[i].brandId").unwrap_or_default();
    let _ = json.string_of("brands[i].brandName").unwrap_or_default();
    let _ = json.string_of("brands[i].errorDetails.errorCode").unwrap_or_default();
    let _ = json.string_of("brands[i].errorDetails.message").unwrap_or_default();
    let _ = json.string_of("brands[i].isOverridingCompanyName").unwrap_or_default();
    let _ = json.string_of("brands[i].isSendingDefault").unwrap_or_default();
    let _ = json.string_of("brands[i].isSigningDefault").unwrap_or_default();
    let _ = json.string_of("brands[i].logos.primary").unwrap_or_default();
    let _ = json.string_of("brands[i].logos.secondary").unwrap_or_default();
    let _ = json.string_of("brands[i].logos.email").unwrap_or_default();
    let _ = json.string_of("brands[i].resources.email").unwrap_or_default();
    let _ = json.string_of("brands[i].resources.sending").unwrap_or_default();
    let _ = json.string_of("brands[i].resources.signing").unwrap_or_default();
    let _ = json.string_of("brands[i].resources.signingCaptive").unwrap_or_default();
    j = 0;
    count_j = json.size_of_array("brands[i].colors");
    while j < count_j {
        json.set_j(j);
        j = j + 1;
    }

    j = 0;
    count_j = json.size_of_array("brands[i].landingPages");
    while j < count_j {
        json.set_j(j);
        j = j + 1;
    }

    j = 0;
    count_j = json.size_of_array("brands[i].links");
    while j < count_j {
        json.set_j(j);
        let _ = json.string_of("brands[i].links[j].linkType").unwrap_or_default();
        let _ = json.string_of("brands[i].links[j].urlOrMailTo").unwrap_or_default();
        let _ = json.string_of("brands[i].links[j].linkText").unwrap_or_default();
        let _ = json.string_of("brands[i].links[j].showLink").unwrap_or_default();
        j = j + 1;
    }

    j = 0;
    count_j = json.size_of_array("brands[i].emailContent");
    while j < count_j {
        json.set_j(j);
        let _ = json.string_of("brands[i].emailContent[j].emailContentType").unwrap_or_default();
        let _ = json.string_of("brands[i].emailContent[j].content").unwrap_or_default();
        let _ = json.string_of("brands[i].emailContent[j].emailToLink").unwrap_or_default();
        let _ = json.string_of("brands[i].emailContent[j].linkText").unwrap_or_default();
        j = j + 1;
    }

    i = i + 1;
}