Sample code for 30+ languages & platforms
Rust

OneNote - Get Page Metadata

See more OneNote Examples

Access a page's metadata by page identifier.

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/me/onenote/pages/{id} \
//   -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("page_id", "0-d2298668edd74dccac7f821fa378bf64!41-3A33FCEB9B74CC15!20350");

let sb_response_body = chilkat::StringBuilder::new();
if http.quick_get_sb("https://graph.microsoft.com/v1.0/me/onenote/pages/{$page_id}", &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#users('admin%40chilkat.io')/onenote/pages/$entity",
//   "id": "0-d2298668edd74dccac7f821fa378bf64!41-3A33FCEB9B74CC15!20350",
//   "self": "https://graph.microsoft.com/v1.0/users/admin@chilkat.io/onenote/pages/0-d2298668edd74dccac7f821fa378bf64!41-3A33FCEB9B74CC15!20350",
//   "createdDateTime": "2020-10-23T12:00:44Z",
//   "title": "A page with rendered images and an attached file",
//   "createdByAppId": "WLID-00000000441C9990",
//   "contentUrl": "https://graph.microsoft.com/v1.0/users/admin@chilkat.io/onenote/pages/0-d2298668edd74dccac7f821fa378bf64!41-3A33FCEB9B74CC15!20350/content",
//   "lastModifiedDateTime": "2020-10-23T17:00:45.9018633Z",
//   "links": {
//     "oneNoteClientUrl": {
//       "href": "onenote:https://d.docs.live.net/3a33fceb9b74cc15/Documents/Testing%20Notebook/Ddd.one#A%20page%20with%20rendered%20images%20and%20an%20attached%20file&section-id=40f1bd0c-f32c-4f6a-8cc8-d0fc782f7064&page-id=2a8949ff-753a-45df-9a4c-f82743a7ebed&end"
//     },
//     "oneNoteWebUrl": {
//       "href": "https://onedrive.live.com/redir.aspx?cid=3a33fceb9b74cc15&page=edit&resid=3A33FCEB9B74CC15!20344&parId=3A33FCEB9B74CC15!187&wd=target%28Ddd.one%7C40f1bd0c-f32c-4f6a-8cc8-d0fc782f7064%2FA%20page%20with%20rendered%20images%20and%20an%20attached%20file%7C2a8949ff-753a-45df-9a4c-f82743a7ebed%2F%29"
//     }
//   },
//   "parentSection@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('admin%40chilkat.io')/onenote/pages('0-d2298668edd74dccac7f821fa378bf64%2141-3A33FCEB9B74CC15%2120350')/parentSection/$entity",
//   "parentSection": {
//     "id": "0-3A33FCEB9B74CC15!20350",
//     "displayName": "Ddd",
//     "self": "https://graph.microsoft.com/v1.0/users/admin@chilkat.io/onenote/sections/0-3A33FCEB9B74CC15!20350"
//   }
// }

// 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 title = j_resp.string_of("title").unwrap_or_default();
let created_by_app_id = j_resp.string_of("createdByAppId").unwrap_or_default();
let content_url = j_resp.string_of("contentUrl").unwrap_or_default();
let last_modified_date_time = j_resp.string_of("lastModifiedDateTime").unwrap_or_default();
let links_one_note_client_url_href = j_resp.string_of("links.oneNoteClientUrl.href").unwrap_or_default();
let links_one_note_web_url_href = j_resp.string_of("links.oneNoteWebUrl.href").unwrap_or_default();
let parent_sectionodata_context = j_resp.string_of("\"parentSection@odata.context\"").unwrap_or_default();
let parent_section_id = j_resp.string_of("parentSection.id").unwrap_or_default();
let parent_section_display_name = j_resp.string_of("parentSection.displayName").unwrap_or_default();
let parent_section_self = j_resp.string_of("parentSection.self").unwrap_or_default();