Sample code for 30+ languages & platforms
Visual FoxPro

OneNote - List Sections

See more OneNote Examples

Retrieve a list of sections from the specified notebook.

Chilkat Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loHttp
LOCAL loSbResponseBody
LOCAL loJResp
LOCAL lnRespStatusCode
LOCAL lcId
LOCAL lcSelf
LOCAL lcCreatedDateTime
LOCAL lcDisplayName
LOCAL lcLastModifiedDateTime
LOCAL lnIsDefault
LOCAL lcPagesUrl
LOCAL lcCreatedByUserId
LOCAL lcCreatedByUserDisplayName
LOCAL lcLastModifiedByUserId
LOCAL lcLastModifiedByUserDisplayName
LOCAL lcParentNotebookodata_context
LOCAL lcParentNotebookId
LOCAL lcParentNotebookDisplayName
LOCAL lcParentNotebookSelf
LOCAL lcParentSectionGroupodata_context
LOCAL lcParentSectionGroup
LOCAL lcOdata_context
LOCAL i
LOCAL lnCount_i

lnSuccess = 0

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

loHttp = CreateObject('Chilkat.Http')

* 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.
loHttp.AuthToken = "ACCESS_TOKEN"

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

loSbResponseBody = CreateObject('Chilkat.StringBuilder')
lnSuccess = loHttp.QuickGetSb("https://graph.microsoft.com/v1.0/me/onenote/notebooks/{$id}/sections",loSbResponseBody)
IF (lnSuccess = 0) THEN
    ? loHttp.LastErrorText
    RELEASE loHttp
    RELEASE loSbResponseBody
    CANCEL
ENDIF

loJResp = CreateObject('Chilkat.JsonObject')
loJResp.LoadSb(loSbResponseBody)
loJResp.EmitCompact = 0

? "Response Body:"
? loJResp.Emit()

lnRespStatusCode = loHttp.LastStatus
? "Response Status Code = " + STR(lnRespStatusCode)
IF (lnRespStatusCode >= 400) THEN
    ? "Response Header:"
    ? loHttp.LastHeader
    ? "Failed."
    RELEASE loHttp
    RELEASE loSbResponseBody
    RELEASE loJResp
    CANCEL
ENDIF

* 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

lcOdata_context = loJResp.StringOf('"@odata.context"')
i = 0
lnCount_i = loJResp.SizeOfArray("value")
DO WHILE i < lnCount_i
    loJResp.I = i
    lcId = loJResp.StringOf("value[i].id")
    lcSelf = loJResp.StringOf("value[i].self")
    lcCreatedDateTime = loJResp.StringOf("value[i].createdDateTime")
    lcDisplayName = loJResp.StringOf("value[i].displayName")
    lcLastModifiedDateTime = loJResp.StringOf("value[i].lastModifiedDateTime")
    lnIsDefault = loJResp.BoolOf("value[i].isDefault")
    lcPagesUrl = loJResp.StringOf("value[i].pagesUrl")
    lcCreatedByUserId = loJResp.StringOf("value[i].createdBy.user.id")
    lcCreatedByUserDisplayName = loJResp.StringOf("value[i].createdBy.user.displayName")
    lcLastModifiedByUserId = loJResp.StringOf("value[i].lastModifiedBy.user.id")
    lcLastModifiedByUserDisplayName = loJResp.StringOf("value[i].lastModifiedBy.user.displayName")
    lcParentNotebookodata_context = loJResp.StringOf('value[i]."parentNotebook@odata.context"')
    lcParentNotebookId = loJResp.StringOf("value[i].parentNotebook.id")
    lcParentNotebookDisplayName = loJResp.StringOf("value[i].parentNotebook.displayName")
    lcParentNotebookSelf = loJResp.StringOf("value[i].parentNotebook.self")
    lcParentSectionGroupodata_context = loJResp.StringOf('value[i]."parentSectionGroup@odata.context"')
    lcParentSectionGroup = loJResp.StringOf("value[i].parentSectionGroup")
    i = i + 1
ENDDO

RELEASE loHttp
RELEASE loSbResponseBody
RELEASE loJResp