Rust Requires Chilkat v11.0.0+
Rust
Outlook -- Create a Mail Folder
See more Outlook Examples
Creates a new mail folder as a child of an existing mail folder.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 here:
http.set_auth_token("MICROSOFT_GRAPH_ACCESS_TOKEN");
// This example will create a new mail folder as a child of /Inbox/abc
// Get the existing folder ID from the folder map created by this example
let ht_folder_map = chilkat::Hashtable::new();
let sb_map = chilkat::StringBuilder::new();
let _ = sb_map.load_file("qa_data/outlook/folderMap.xml", "utf-8");
let _ = ht_folder_map.add_from_xml_sb(&sb_map);
let Ok(existing_folder_id) = ht_folder_map.lookup_str("/Inbox/abc") else {
println!("Folder ID not found");
return;
};
// Create a JSON request body with this content:
//
// {
// "displayName": "displayName-value",
// }
// This example will create /Inbox/abc/subFolderC
let json_request_body = chilkat::JsonObject::new();
let _ = json_request_body.update_string("displayName", "subFolderC");
let _ = http.set_url_var("folder_id", &existing_folder_id);
// Create the folder "subFolderC" at the specified location.
let resp = chilkat::HttpResponse::new();
if http.http_json("POST", "https://graph.microsoft.com/v1.0/me/mailFolders/{$folder_id}/childFolders", &json_request_body, "application/json", &resp).is_err() {
println!("{}", http.last_error_text());
return;
}
// A 201 response indicates success.
if http.last_status() == 201 {
println!("Folder created.");
} else {
println!("Response status code = {}", resp.status_code());
println!("Error: Folder not created.");
}
// Show the response in both cases..
let json_response = chilkat::JsonObject::new();
json_response.set_emit_compact(false);
let _ = json_response.load(&resp.body_str());
println!("{}", json_response.emit().unwrap_or_default());
// A sample successful JSON response looks like this:
// {
// "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('me')/mailFolders('AQMkADAwATM0MDAAMS1iNTcwLWI2NTEtMDACLTAwCgAuAAADsVyfxjDU406Ic4X7ill8xAEA5_vF7TKKdE6bGCRqXyl2PQAAAL8huv8AAAA%3D')/childFolders/$entity",
// "id": "AQMkADAwATM0MDAAMS1iNTcwLWI2NTEtMDACLTAwCgAuAAADsVyfxjDU406Ic4X7ill8xAEA5_vF7TKKdE6bGCRqXyl2PQAAAM6JqMIAAAA=",
// "displayName": "subFolderC",
// "parentFolderId": "AQMkADAwATM0MDAAMS1iNTcwLWI2NTEtMDACLTAwCgAuAAADsVyfxjDU406Ic4X7ill8xAEA5_vF7TKKdE6bGCRqXyl2PQAAAL8huv8AAAA=",
// "childFolderCount": 0,
// "unreadItemCount": 0,
// "totalItemCount": 0
// }