Rust Requires Chilkat v11.0.0+
Rust
Create Group
See more Microsoft Group Examples
Create a new group as specified in the request body. You can create one of three types of groups:- Office 365 Group (unified group)
- Dynamic group
- Security group
This operation returns by default only a subset of the properties for each group. These default properties are noted in the Properties section.
See https://docs.microsoft.com/en-us/graph/api/group-post-groups?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());
// Create a JSON body for the HTTP POST
// Use this online tool to generate the code from sample JSON:
// Generate Code to Create JSON
// {
// "description": "Self help community for library",
// "displayName": "Library Assist",
// "groupTypes": [
// "Unified"
// ],
// "mailEnabled": true,
// "mailNickname": "library",
// "securityEnabled": false
// }
let json = chilkat::JsonObject::new();
let _ = json.update_string("description", "Self help community for library");
let _ = json.update_string("displayName", "Library Assist");
let _ = json.update_string("groupTypes[0]", "Unified");
let _ = json.update_bool("mailEnabled", true);
let _ = json.update_string("mailNickname", "library");
let _ = json.update_bool("securityEnabled", false);
// POST the JSON to https://graph.microsoft.com/v1.0/groups
let resp = chilkat::HttpResponse::new();
if http.http_json("POST", "https://graph.microsoft.com/v1.0/groups", &json, "application/json", &resp).is_err() {
println!("{}", http.last_error_text());
return;
}
let _ = json.load(&resp.body_str());
json.set_emit_compact(false);
if resp.status_code() != 201 {
println!("{}", json.emit().unwrap_or_default());
println!("Failed, response status code = {}", resp.status_code());
return;
}
println!("{}", json.emit().unwrap_or_default());
// A sample response:
// (See code for parsing this response below..)
// {
// "id": "b320ee12-b1cd-4cca-b648-a437be61c5cd",
// "deletedDateTime": null,
// "classification": null,
// "createdDateTime": "2018-12-22T00:51:37Z",
// "creationOptions": [],
// "description": "Self help community for library",
// "displayName": "Library Assist",
// "groupTypes": [
// "Unified"
// ],
// "mail": "library7423@contoso.com",
// "mailEnabled": true,
// "mailNickname": "library",
// "onPremisesLastSyncDateTime": null,
// "onPremisesSecurityIdentifier": null,
// "onPremisesSyncEnabled": null,
// "preferredDataLocation": "CAN",
// "proxyAddresses": [
// "SMTP:library7423@contoso.com"
// ],
// "renewedDateTime": "2018-12-22T00:51:37Z",
// "resourceBehaviorOptions": [],
// "resourceProvisioningOptions": [],
// "securityEnabled": false,
// "visibility": "Public",
// "onPremisesProvisioningErrors": []
// }
// Use this online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
let mut i: i32 = 0;
let mut count_i: i32 = 0;
let id = json.string_of("id").unwrap_or_default();
let deleted_date_time = json.string_of("deletedDateTime").unwrap_or_default();
let classification = json.string_of("classification").unwrap_or_default();
let created_date_time = json.string_of("createdDateTime").unwrap_or_default();
let description = json.string_of("description").unwrap_or_default();
let display_name = json.string_of("displayName").unwrap_or_default();
let mail = json.string_of("mail").unwrap_or_default();
let mail_enabled = json.bool_of("mailEnabled");
let mail_nickname = json.string_of("mailNickname").unwrap_or_default();
let on_premises_last_sync_date_time = json.string_of("onPremisesLastSyncDateTime").unwrap_or_default();
let on_premises_security_identifier = json.string_of("onPremisesSecurityIdentifier").unwrap_or_default();
let on_premises_sync_enabled = json.string_of("onPremisesSyncEnabled").unwrap_or_default();
let preferred_data_location = json.string_of("preferredDataLocation").unwrap_or_default();
let renewed_date_time = json.string_of("renewedDateTime").unwrap_or_default();
let security_enabled = json.bool_of("securityEnabled");
let visibility = json.string_of("visibility").unwrap_or_default();
i = 0;
count_i = json.size_of_array("creationOptions");
while i < count_i {
json.set_i(i);
i = i + 1;
}
i = 0;
count_i = json.size_of_array("groupTypes");
while i < count_i {
json.set_i(i);
let _ = json.string_of("groupTypes[i]").unwrap_or_default();
i = i + 1;
}
i = 0;
count_i = json.size_of_array("proxyAddresses");
while i < count_i {
json.set_i(i);
let _ = json.string_of("proxyAddresses[i]").unwrap_or_default();
i = i + 1;
}
i = 0;
count_i = json.size_of_array("resourceBehaviorOptions");
while i < count_i {
json.set_i(i);
// ...
i = i + 1;
}
i = 0;
count_i = json.size_of_array("resourceProvisioningOptions");
while i < count_i {
json.set_i(i);
// ...
i = i + 1;
}
i = 0;
count_i = json.size_of_array("onPremisesProvisioningErrors");
while i < count_i {
json.set_i(i);
// ...
i = i + 1;
}
println!("Success.");