Sample code for 30+ languages & platforms
Rust

Outlook List Contacts

See more Outlook Contact Examples

List Outlook Contacts

Chilkat Rust Downloads

Rust

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

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

// Use your previously obtained access token here: Get Outlook Contacts OAuth2 Access Token (Azure AD v2.0 Endpoint).

let json_token = chilkat::JsonObject::new();
if json_token.load_file("qa_data/tokens/outlookContacts.json").is_err() {
    println!("{}", json_token.last_error_text());
    return;
}

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

// Send the following GET:

// GET https://graph.microsoft.com/v1.0/me/contacts
let sb_json = chilkat::StringBuilder::new();
if http.quick_get_sb("https://graph.microsoft.com/v1.0/me/contacts", &sb_json).is_err() {
    println!("{}", http.last_error_text());
    return;
}

let status_code = http.last_status();
println!("Response status code = {}", status_code);

if status_code != 200 {
    println!("{}", sb_json.get_as_string().unwrap_or_default());
    println!("Failed.");
    return;
}

let j_resp = chilkat::JsonObject::new();
let _ = j_resp.load_sb(&sb_json);
j_resp.set_emit_compact(false);
println!("{}", j_resp.emit().unwrap_or_default());

// Sample output:

// Use this online tool to generate parsing code from sample JSON: 
// Generate Parsing Code from JSON

// {
//   "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('4ee732c3-322e-4a6b-b729-2fd1eb5c6004')/contacts",
//   "value": [
//     {
//       "@odata.etag": "W/\"EQAAABYAAABUcG0qWqkmQYqWLHQataQxAAD0iYfT\"",
//       "id": "AAMkADYzZWE3YmZmLWU0YzgtNGNkZC04MGE1LWFiYTFlNTRlY2QwYQBGAAAAAAAu7cUXL5YOTrdsUIw7-v8FBwBUcG0qWqkmQYqWLHQataQxAAAAAAEOAABUcG0qWqkmQYqWLHQataQxAAD0sxexAAA=",
//       "createdDateTime": "2021-06-29T16:32:05Z",
//       "lastModifiedDateTime": "2021-06-29T16:32:06Z",
//       "changeKey": "EQAAABYAAABUcG0qWqkmQYqWLHQataQxAAD0iYfT",
//       "categories": [
//       ],
//       "parentFolderId": "AAMkADYzZWE3YmZmLWU0YzgtNGNkZC04MGE1LWFiYTFlNTRlY2QwYQAuAAAAAAAu7cUXL5YOTrdsUIw7-v8FAQBUcG0qWqkmQYqWLHQataQxAAAAAAEOAAA=",
//       "birthday": null,
//       "fileAs": "",
//       "displayName": "Pavel Bansky",
//       "givenName": "Pavel",
//       "initials": null,
//       "middleName": null,
//       "nickName": null,
//       "surname": "Bansky",
//       "title": null,
//       "yomiGivenName": null,
//       "yomiSurname": null,
//       "yomiCompanyName": null,
//       "generation": null,
//       "imAddresses": [
//       ],
//       "jobTitle": null,
//       "companyName": null,
//       "department": null,
//       "officeLocation": null,
//       "profession": null,
//       "businessHomePage": null,
//       "assistantName": null,
//       "manager": null,
//       "homePhones": [
//       ],
//       "mobilePhone": null,
//       "businessPhones": [
//         "+1 732 555 0102"
//       ],
//       "spouseName": null,
//       "personalNotes": "",
//       "children": [
//       ],
//       "emailAddresses": [
//         {
//           "name": "Pavel Bansky",
//           "address": "pavelb@fabrikam.onmicrosoft.com"
//         }
//       ],
//       "homeAddress": {},
//       "businessAddress": {},
//       "otherAddress": {}
//     },
// ...
//   ]
// }

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

let odata_context = j_resp.string_of("\"@odata.context\"").unwrap_or_default();
let mut i = 0;
let count_i = j_resp.size_of_array("value");
while i < count_i {
    j_resp.set_i(i);
    let _ = j_resp.string_of("value[i].\"@odata.etag\"").unwrap_or_default();
    let _ = j_resp.string_of("value[i].id").unwrap_or_default();
    let _ = j_resp.string_of("value[i].createdDateTime").unwrap_or_default();
    let _ = j_resp.string_of("value[i].lastModifiedDateTime").unwrap_or_default();
    let _ = j_resp.string_of("value[i].changeKey").unwrap_or_default();
    let _ = j_resp.string_of("value[i].parentFolderId").unwrap_or_default();
    let _ = j_resp.string_of("value[i].birthday").unwrap_or_default();
    let _ = j_resp.string_of("value[i].fileAs").unwrap_or_default();
    let _ = j_resp.string_of("value[i].displayName").unwrap_or_default();
    let _ = j_resp.string_of("value[i].givenName").unwrap_or_default();
    let _ = j_resp.string_of("value[i].initials").unwrap_or_default();
    let _ = j_resp.string_of("value[i].middleName").unwrap_or_default();
    let _ = j_resp.string_of("value[i].nickName").unwrap_or_default();
    let _ = j_resp.string_of("value[i].surname").unwrap_or_default();
    let _ = j_resp.string_of("value[i].title").unwrap_or_default();
    let _ = j_resp.string_of("value[i].yomiGivenName").unwrap_or_default();
    let _ = j_resp.string_of("value[i].yomiSurname").unwrap_or_default();
    let _ = j_resp.string_of("value[i].yomiCompanyName").unwrap_or_default();
    let _ = j_resp.string_of("value[i].generation").unwrap_or_default();
    let _ = j_resp.string_of("value[i].jobTitle").unwrap_or_default();
    let _ = j_resp.string_of("value[i].companyName").unwrap_or_default();
    let _ = j_resp.string_of("value[i].department").unwrap_or_default();
    let _ = j_resp.string_of("value[i].officeLocation").unwrap_or_default();
    let _ = j_resp.string_of("value[i].profession").unwrap_or_default();
    let _ = j_resp.string_of("value[i].businessHomePage").unwrap_or_default();
    let _ = j_resp.string_of("value[i].assistantName").unwrap_or_default();
    let _ = j_resp.string_of("value[i].manager").unwrap_or_default();
    let _ = j_resp.string_of("value[i].mobilePhone").unwrap_or_default();
    let _ = j_resp.string_of("value[i].spouseName").unwrap_or_default();
    let _ = j_resp.string_of("value[i].personalNotes").unwrap_or_default();
    j = 0;
    count_j = j_resp.size_of_array("value[i].categories");
    while j < count_j {
        j_resp.set_j(j);
        j = j + 1;
    }

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

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

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

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

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

    i = i + 1;
}