Sample code for 30+ languages & platforms
Rust

Microsoft Teams - List Team Members

See more Microsoft Teams Examples

Get the members of a team.

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 -X GET https://graph.microsoft.com/v1.0/teams/{teamsId}/members \
//   -H 'authorization: Bearer ACCESS_TOKEN'

// 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 ACCESS_TOKEN" header.
http.set_auth_token("ACCESS_TOKEN");

let _ = http.set_url_var("teamsId", "285c8d65-d8b5-447a-91c7-85593d50c826");

let sb_response_body = chilkat::StringBuilder::new();
if http.quick_get_sb("https://graph.microsoft.com/v1.0/teams/{$teamsId}/members", &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_header());
    println!("Failed.");
    return;
}

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

// {
//   "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#teams('285c8d65-d8b5-447a-91c7-85593d50c826')/members",
//   "@odata.count": 1,
//   "value": [
//     {
//       "@odata.type": "#microsoft.graph.aadUserConversationMember",
//       "id": "Mjg1YzhkNjUtZDhiNS00NDdhLTkxYzctODU1OTNkNTBjODI2IyM0ZWU3MzJjMz0zMjJlLTRhNmItYjcyOS0yZmQxZWI1YzYwMDQ=",
//       "roles": [
//         "owner"
//       ],
//       "displayName": "Joe Smith",
//       "userId": "4ee732c3-322e-4a6b-b729-2fd1eb5c6004",
//       "email": "admin@chilkat365.com"
//     }
//   ]
// }

// 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 odata_context = j_resp.string_of("\"@odata.context\"").unwrap_or_default();
let odata_count = j_resp.int_of("\"@odata.count\"");
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.type\"").unwrap_or_default();
    let _ = j_resp.string_of("value[i].id").unwrap_or_default();
    let _ = j_resp.string_of("value[i].displayName").unwrap_or_default();
    let _ = j_resp.string_of("value[i].userId").unwrap_or_default();
    let _ = j_resp.string_of("value[i].email").unwrap_or_default();
    j = 0;
    count_j = j_resp.size_of_array("value[i].roles");
    while j < count_j {
        j_resp.set_j(j);
        let _ = j_resp.string_of("value[i].roles[j]").unwrap_or_default();
        j = j + 1;
    }

    i = i + 1;
}