Sample code for 30+ languages & platforms
PowerBuilder

OneNote - List Sections

See more OneNote Examples

Retrieve a list of sections from the specified notebook.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Http
oleobject loo_SbResponseBody
oleobject loo_JResp
integer li_RespStatusCode
string ls_Id
string ls_Self
string ls_CreatedDateTime
string ls_DisplayName
string ls_LastModifiedDateTime
integer li_IsDefault
string ls_PagesUrl
string ls_CreatedByUserId
string ls_CreatedByUserDisplayName
string ls_LastModifiedByUserId
string ls_LastModifiedByUserDisplayName
string ls_ParentNotebookodata_context
string ls_ParentNotebookId
string ls_ParentNotebookDisplayName
string ls_ParentNotebookSelf
string ls_ParentSectionGroupodata_context
string ls_ParentSectionGroup
string ls_Odata_context
integer i
integer li_Count_i

li_Success = 0

// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
    destroy loo_Http
    MessageBox("Error","Connecting to COM object failed")
    return
end if

// Implements the following CURL command:

// curl -X GET https://graph.microsoft.com/v1.0/me/onenote/notebooks \
//   -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.
loo_Http.AuthToken = "ACCESS_TOKEN"

loo_Http.SetUrlVar("id","0-3A33FCEB9B74CC15!20344")

loo_SbResponseBody = create oleobject
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat.StringBuilder")

li_Success = loo_Http.QuickGetSb("https://graph.microsoft.com/v1.0/me/onenote/notebooks/{$id}/sections",loo_SbResponseBody)
if li_Success = 0 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_SbResponseBody
    return
end if

loo_JResp = create oleobject
li_rc = loo_JResp.ConnectToNewObject("Chilkat.JsonObject")

loo_JResp.LoadSb(loo_SbResponseBody)
loo_JResp.EmitCompact = 0

Write-Debug "Response Body:"
Write-Debug loo_JResp.Emit()

li_RespStatusCode = loo_Http.LastStatus
Write-Debug "Response Status Code = " + string(li_RespStatusCode)
if li_RespStatusCode >= 400 then
    Write-Debug "Response Header:"
    Write-Debug loo_Http.LastHeader
    Write-Debug "Failed."
    destroy loo_Http
    destroy loo_SbResponseBody
    destroy loo_JResp
    return
end if

// 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",
//   "value": [
//     {
//       "id": "0-3A33FCEB9B74CC15!20347",
//       "self": "https://graph.microsoft.com/v1.0/users/admin@chilkat.io/onenote/sections/0-3A33FCEB9B74CC15!20347",
//       "createdDateTime": "2020-10-22T22:39:58.247Z",
//       "displayName": "Aaa",
//       "lastModifiedDateTime": "2020-10-22T22:40:00.363Z",
//       "isDefault": false,
//       "pagesUrl": "https://graph.microsoft.com/v1.0/users/admin@chilkat.io/onenote/sections/0-3A33FCEB9B74CC15!20347/pages",
//       "createdBy": {
//         "user": {
//           "id": "3A33FCEB9B74CC15",
//           "displayName": "Matt Smith"
//         }
//       },
//       "lastModifiedBy": {
//         "user": {
//           "id": "3A33FCEB9B74CC15",
//           "displayName": "Matt Smith"
//         }
//       },
//       "parentNotebook@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('admin%40chilkat.io')/onenote/notebooks('0-3A33FCEB9B74CC15%2120344')/sections('0-3A33FCEB9B74CC15%2120347')/parentNotebook/$entity",
//       "parentNotebook": {
//         "id": "0-3A33FCEB9B74CC15!20344",
//         "displayName": "Testing Notebook",
//         "self": "https://graph.microsoft.com/v1.0/users/admin@chilkat.io/onenote/notebooks/0-3A33FCEB9B74CC15!20344"
//       },
//       "parentSectionGroup@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('admin%40chilkat.io')/onenote/notebooks('0-3A33FCEB9B74CC15%2120344')/sections('0-3A33FCEB9B74CC15%2120347')/parentSectionGroup/$entity",
//       "parentSectionGroup": null
//     },
//     {
//       "id": "0-3A33FCEB9B74CC15!20348",
//       "self": "https://graph.microsoft.com/v1.0/users/admin@chilkat.io/onenote/sections/0-3A33FCEB9B74CC15!20348",
//       "createdDateTime": "2020-10-22T22:40:09.227Z",
//       "displayName": "Bbb",
//       "lastModifiedDateTime": "2020-10-22T22:40:12.21Z",
//       "isDefault": false,
//       "pagesUrl": "https://graph.microsoft.com/v1.0/users/admin@chilkat.io/onenote/sections/0-3A33FCEB9B74CC15!20348/pages",
//       "createdBy": {
//         "user": {
//           "id": "3A33FCEB9B74CC15",
//           "displayName": "Matt Smith"
//         }
//       },
//       "lastModifiedBy": {
//         "user": {
//           "id": "3A33FCEB9B74CC15",
//           "displayName": "Matt Smith"
//         }
//       },
//       "parentNotebook@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('admin%40chilkat.io')/onenote/notebooks('0-3A33FCEB9B74CC15%2120344')/sections('0-3A33FCEB9B74CC15%2120348')/parentNotebook/$entity",
//       "parentNotebook": {
//         "id": "0-3A33FCEB9B74CC15!20344",
//         "displayName": "Testing Notebook",
//         "self": "https://graph.microsoft.com/v1.0/users/admin@chilkat.io/onenote/notebooks/0-3A33FCEB9B74CC15!20344"
//       },
//       "parentSectionGroup@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('admin%40chilkat.io')/onenote/notebooks('0-3A33FCEB9B74CC15%2120344')/sections('0-3A33FCEB9B74CC15%2120348')/parentSectionGroup/$entity",
//       "parentSectionGroup": null
//     },
//     {
//       "id": "0-3A33FCEB9B74CC15!20349",
//       "self": "https://graph.microsoft.com/v1.0/users/admin@chilkat.io/onenote/sections/0-3A33FCEB9B74CC15!20349",
//       "createdDateTime": "2020-10-22T22:40:12.517Z",
//       "displayName": "Ccc",
//       "lastModifiedDateTime": "2020-10-22T22:40:14.367Z",
//       "isDefault": false,
//       "pagesUrl": "https://graph.microsoft.com/v1.0/users/admin@chilkat.io/onenote/sections/0-3A33FCEB9B74CC15!20349/pages",
//       "createdBy": {
//         "user": {
//           "id": "3A33FCEB9B74CC15",
//           "displayName": "Matt Smith"
//         }
//       },
//       "lastModifiedBy": {
//         "user": {
//           "id": "3A33FCEB9B74CC15",
//           "displayName": "Matt Smith"
//         }
//       },
//       "parentNotebook@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('admin%40chilkat.io')/onenote/notebooks('0-3A33FCEB9B74CC15%2120344')/sections('0-3A33FCEB9B74CC15%2120349')/parentNotebook/$entity",
//       "parentNotebook": {
//         "id": "0-3A33FCEB9B74CC15!20344",
//         "displayName": "Testing Notebook",
//         "self": "https://graph.microsoft.com/v1.0/users/admin@chilkat.io/onenote/notebooks/0-3A33FCEB9B74CC15!20344"
//       },
//       "parentSectionGroup@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('admin%40chilkat.io')/onenote/notebooks('0-3A33FCEB9B74CC15%2120344')/sections('0-3A33FCEB9B74CC15%2120349')/parentSectionGroup/$entity",
//       "parentSectionGroup": null
//     }
//   ]
// }

// Sample code for parsing the JSON response...
// Use the following online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON

ls_Odata_context = loo_JResp.StringOf("~"@odata.context~"")
i = 0
li_Count_i = loo_JResp.SizeOfArray("value")
do while i < li_Count_i
    loo_JResp.I = i
    ls_Id = loo_JResp.StringOf("value[i].id")
    ls_Self = loo_JResp.StringOf("value[i].self")
    ls_CreatedDateTime = loo_JResp.StringOf("value[i].createdDateTime")
    ls_DisplayName = loo_JResp.StringOf("value[i].displayName")
    ls_LastModifiedDateTime = loo_JResp.StringOf("value[i].lastModifiedDateTime")
    li_IsDefault = loo_JResp.BoolOf("value[i].isDefault")
    ls_PagesUrl = loo_JResp.StringOf("value[i].pagesUrl")
    ls_CreatedByUserId = loo_JResp.StringOf("value[i].createdBy.user.id")
    ls_CreatedByUserDisplayName = loo_JResp.StringOf("value[i].createdBy.user.displayName")
    ls_LastModifiedByUserId = loo_JResp.StringOf("value[i].lastModifiedBy.user.id")
    ls_LastModifiedByUserDisplayName = loo_JResp.StringOf("value[i].lastModifiedBy.user.displayName")
    ls_ParentNotebookodata_context = loo_JResp.StringOf("value[i].~"parentNotebook@odata.context~"")
    ls_ParentNotebookId = loo_JResp.StringOf("value[i].parentNotebook.id")
    ls_ParentNotebookDisplayName = loo_JResp.StringOf("value[i].parentNotebook.displayName")
    ls_ParentNotebookSelf = loo_JResp.StringOf("value[i].parentNotebook.self")
    ls_ParentSectionGroupodata_context = loo_JResp.StringOf("value[i].~"parentSectionGroup@odata.context~"")
    ls_ParentSectionGroup = loo_JResp.StringOf("value[i].parentSectionGroup")
    i = i + 1
loop


destroy loo_Http
destroy loo_SbResponseBody
destroy loo_JResp