Rust
Rust
OneNote - Create Section
See more OneNote Examples
Creates a new notebook section in Microsoft OneNoteChilkat Rust Downloads
// 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 POST https://graph.microsoft.com/v1.0/me/onenote/notebooks/{notebook_id}/sections \
// -H 'authorization: Bearer ACCESS_TOKEN'
// -H "Content-type: application/json" \
// -d '{
// "displayName": "Section name"
// }'
// Use the following online tool to generate HTTP code from a CURL command
// Convert a cURL Command to HTTP Source Code
// Use this online tool to generate code from sample JSON:
// Generate Code to Create JSON
// The following JSON is sent in the request body.
// {
// "displayName": "Ddd"
// }
// Create a new section named "Ddd"
let json = chilkat::JsonObject::new();
let _ = json.update_string("displayName", "Ddd");
http.set_request_header("Content-type", "application/json");
// Adds the "Authorization: Bearer ACCESS_TOKEN" header.
http.set_auth_token("ACCESS_TOKEN");
let _ = http.set_url_var("notebook_id", "0-3A33FCEB9B74CC15!20344");
let resp = chilkat::HttpResponse::new();
if http.http_json("POST", "https://graph.microsoft.com/v1.0/me/onenote/notebooks/{$notebook_id}/sections", &json, "application/json", &resp).is_err() {
println!("{}", http.last_error_text());
return;
}
let sb_response_body = chilkat::StringBuilder::new();
let _ = resp.get_body_sb(&sb_response_body);
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 = resp.status_code();
println!("Response Status Code = {}", resp_status_code);
if resp_status_code >= 400 {
println!("Response Header:");
println!("{}", resp.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#users('admin%40chilkat.io')/onenote/notebooks('0-3A33FCEB9B74CC15%2120344')/sections/$entity",
// "id": "0-3A33FCEB9B74CC15!20350",
// "self": "https://graph.microsoft.com/v1.0/users/admin@chilkat.io/onenote/sections/0-3A33FCEB9B74CC15!20350",
// "createdDateTime": "2020-10-22T23:22:30.673Z",
// "displayName": "Ddd",
// "lastModifiedDateTime": "2020-10-22T23:22:30.803Z",
// "isDefault": false,
// "pagesUrl": "https://graph.microsoft.com/v1.0/users/admin@chilkat.io/onenote/sections/0-3A33FCEB9B74CC15!20350/pages",
// "createdBy": {
// "user": {
// "id": "3A33FCEB9B74CC15",
// "displayName": "Matt Smith"
// }
// },
// "lastModifiedBy": {
// "user": {
// "id": "3A33FCEB9B74CC15",
// "displayName": "Matt Smith"
// }
// }
// }
// 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 odata_context = j_resp.string_of("\"@odata.context\"").unwrap_or_default();
let id = j_resp.string_of("id").unwrap_or_default();
let self_ = j_resp.string_of("self").unwrap_or_default();
let created_date_time = j_resp.string_of("createdDateTime").unwrap_or_default();
let display_name = j_resp.string_of("displayName").unwrap_or_default();
let last_modified_date_time = j_resp.string_of("lastModifiedDateTime").unwrap_or_default();
let is_default = j_resp.bool_of("isDefault");
let pages_url = j_resp.string_of("pagesUrl").unwrap_or_default();
let created_by_user_id = j_resp.string_of("createdBy.user.id").unwrap_or_default();
let created_by_user_display_name = j_resp.string_of("createdBy.user.displayName").unwrap_or_default();
let last_modified_by_user_id = j_resp.string_of("lastModifiedBy.user.id").unwrap_or_default();
let last_modified_by_user_display_name = j_resp.string_of("lastModifiedBy.user.displayName").unwrap_or_default();