Rust
Rust
List Groups
See more Microsoft Group Examples
List all the groups available in an organization, including but not limited to Office 365 Groups.See https://docs.microsoft.com/en-us/graph/api/group-list?view=graph-rest-1.0 for more information.
Chilkat Rust Downloads
// 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 as shown here:
// Get Microsoft Graph OAuth2 Access Token with Group.ReadWrite.All scope.
let json_token = chilkat::JsonObject::new();
if json_token.load_file("qa_data/tokens/msGraphGroup.json").is_err() {
println!("{}", json_token.last_error_text());
return;
}
http.set_auth_token(&json_token.string_of("access_token").unwrap_or_default());
// Send a GET request to https://graph.microsoft.com/v1.0/groups?$orderby=displayName
let Ok(str_response) = http.quick_get_str("https://graph.microsoft.com/v1.0/groups?$orderby=displayName") else {
println!("{}", http.last_error_text());
return;
};
let json = chilkat::JsonObject::new();
let _ = json.load(&str_response);
json.set_emit_compact(false);
if http.last_status() != 200 {
println!("{}", json.emit().unwrap_or_default());
println!("Failed, response status code = {}", http.last_status());
return;
}
println!("{}", json.emit().unwrap_or_default());
// Sample output:
// (See parsing code below..)
// {
// "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#groups",
// "value": [
// {
// "id": "45b7d2e7-b882-4a80-ba97-10b7a63b8fa4",
// "deletedDateTime": null,
// "classification": null,
// "createdDateTime": "2018-12-22T02:21:05Z",
// "creationOptions": [],
// "description": "Self help community for golf",
// "displayName": "Golf Assist",
// "groupTypes": [
// "Unified"
// ],
// "mail": "golfassist@contoso.com",
// "mailEnabled": true,
// "mailNickname": "golfassist",
// "onPremisesLastSyncDateTime": null,
// "onPremisesSecurityIdentifier": null,
// "onPremisesSyncEnabled": null,
// "preferredDataLocation": "CAN",
// "proxyAddresses": [
// "smtp:golfassist@contoso.onmicrosoft.com",
// "SMTP:golfassist@contoso.com"
// ],
// "renewedDateTime": "2018-12-22T02:21:05Z",
// "resourceBehaviorOptions": [],
// "resourceProvisioningOptions": [],
// "securityEnabled": false,
// "visibility": "Public",
// "onPremisesProvisioningErrors": []
// },
// {
// "id": "d7797254-3084-44d0-99c9-a3b5ab149538",
// "deletedDateTime": null,
// "classification": null,
// "createdDateTime": "2018-11-19T20:29:40Z",
// "creationOptions": [],
// "description": "Talk about golf",
// "displayName": "Golf Discussion",
// "groupTypes": [],
// "mail": "golftalk@contoso.com",
// "mailEnabled": true,
// "mailNickname": "golftalk",
// "onPremisesLastSyncDateTime": null,
// "onPremisesSecurityIdentifier": null,
// "onPremisesSyncEnabled": null,
// "preferredDataLocation": "CAN",
// "proxyAddresses": [
// "smtp:golftalk@contoso.onmicrosoft.com",
// "SMTP:golftalk@contoso.com"
// ],
// "renewedDateTime": "2018-11-19T20:29:40Z",
// "resourceBehaviorOptions": [],
// "resourceProvisioningOptions": [],
// "securityEnabled": false,
// "visibility": null,
// "onPremisesProvisioningErrors": []
// }
// ]
// }
//
// Use this online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
let mut i: i32 = 0;
let mut j: i32 = 0;
let mut count_j: i32 = 0;
let odata_context = json.string_of("\"@odata.context\"").unwrap_or_default();
i = 0;
let count_i = json.size_of_array("value");
while i < count_i {
json.set_i(i);
let _ = json.string_of("value[i].id").unwrap_or_default();
let _ = json.string_of("value[i].deletedDateTime").unwrap_or_default();
let _ = json.string_of("value[i].classification").unwrap_or_default();
let _ = json.string_of("value[i].createdDateTime").unwrap_or_default();
let _ = json.string_of("value[i].description").unwrap_or_default();
let _ = json.string_of("value[i].displayName").unwrap_or_default();
let _ = json.string_of("value[i].mail").unwrap_or_default();
let _ = json.bool_of("value[i].mailEnabled");
let _ = json.string_of("value[i].mailNickname").unwrap_or_default();
let _ = json.string_of("value[i].onPremisesLastSyncDateTime").unwrap_or_default();
let _ = json.string_of("value[i].onPremisesSecurityIdentifier").unwrap_or_default();
let _ = json.string_of("value[i].onPremisesSyncEnabled").unwrap_or_default();
let _ = json.string_of("value[i].preferredDataLocation").unwrap_or_default();
let _ = json.string_of("value[i].renewedDateTime").unwrap_or_default();
let _ = json.bool_of("value[i].securityEnabled");
let _ = json.string_of("value[i].visibility").unwrap_or_default();
j = 0;
count_j = json.size_of_array("value[i].creationOptions");
while j < count_j {
json.set_j(j);
// ...
j = j + 1;
}
j = 0;
count_j = json.size_of_array("value[i].groupTypes");
while j < count_j {
json.set_j(j);
let _ = json.string_of("value[i].groupTypes[j]").unwrap_or_default();
j = j + 1;
}
j = 0;
count_j = json.size_of_array("value[i].proxyAddresses");
while j < count_j {
json.set_j(j);
let _ = json.string_of("value[i].proxyAddresses[j]").unwrap_or_default();
j = j + 1;
}
j = 0;
count_j = json.size_of_array("value[i].resourceBehaviorOptions");
while j < count_j {
json.set_j(j);
// ...
j = j + 1;
}
j = 0;
count_j = json.size_of_array("value[i].resourceProvisioningOptions");
while j < count_j {
json.set_j(j);
// ...
j = j + 1;
}
j = 0;
count_j = json.size_of_array("value[i].onPremisesProvisioningErrors");
while j < count_j {
json.set_j(j);
// ...
j = j + 1;
}
i = i + 1;
}
println!("Success.");