DataFlex
DataFlex
OneNote - Create Notebook
See more OneNote Examples
Creates a new notebook in Microsoft OneNoteChilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoHttp
Variant vJson
Handle hoJson
Variant vResp
Handle hoResp
Variant vSbResponseBody
Handle hoSbResponseBody
Handle hoJResp
Integer iRespStatusCode
String sOdata_context
String sId
String sSelf
String sCreatedDateTime
String sDisplayName
String sLastModifiedDateTime
Boolean iIsDefault
String sUserRole
Boolean iIsShared
String sSectionsUrl
String sSectionGroupsUrl
String sCreatedByUserId
String sCreatedByUserDisplayName
String sLastModifiedByUserId
String sLastModifiedByUserDisplayName
String sLinksOneNoteClientUrlHref
String sLinksOneNoteWebUrlHref
String sTemp1
Move False To iSuccess
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Get Create (RefClass(cComChilkatHttp)) To hoHttp
If (Not(IsComObjectCreated(hoHttp))) Begin
Send CreateComObject of hoHttp
End
// Implements the following CURL command:
// curl -X POST https://graph.microsoft.com/v1.0/me/onenote/notebooks \
// -H 'authorization: Bearer ACCESS_TOKEN'
// -H "Content-type: application/json" \
// -d '{
// "displayName": "Notebook 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": "Testing Notebook"
// }
Get Create (RefClass(cComChilkatJsonObject)) To hoJson
If (Not(IsComObjectCreated(hoJson))) Begin
Send CreateComObject of hoJson
End
Get ComUpdateString Of hoJson "displayName" "Testing Notebook" To iSuccess
Send ComSetRequestHeader To hoHttp "Content-type" "application/json"
// Adds the "Authorization: Bearer ACCESS_TOKEN" header.
Set ComAuthToken Of hoHttp To "ACCESS_TOKEN"
Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
If (Not(IsComObjectCreated(hoResp))) Begin
Send CreateComObject of hoResp
End
Get pvComObject of hoJson to vJson
Get pvComObject of hoResp to vResp
Get ComHttpJson Of hoHttp "POST" "https://graph.microsoft.com/v1.0/me/onenote/notebooks" vJson "application/json" vResp To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoHttp To sTemp1
Showln sTemp1
Procedure_Return
End
Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody
If (Not(IsComObjectCreated(hoSbResponseBody))) Begin
Send CreateComObject of hoSbResponseBody
End
Get pvComObject of hoSbResponseBody to vSbResponseBody
Get ComGetBodySb Of hoResp vSbResponseBody To iSuccess
Get Create (RefClass(cComChilkatJsonObject)) To hoJResp
If (Not(IsComObjectCreated(hoJResp))) Begin
Send CreateComObject of hoJResp
End
Get pvComObject of hoSbResponseBody to vSbResponseBody
Get ComLoadSb Of hoJResp vSbResponseBody To iSuccess
Set ComEmitCompact Of hoJResp To False
Showln "Response Body:"
Get ComEmit Of hoJResp To sTemp1
Showln sTemp1
Get ComStatusCode Of hoResp To iRespStatusCode
Showln "Response Status Code = " iRespStatusCode
If (iRespStatusCode >= 400) Begin
Showln "Response Header:"
Get ComHeader Of hoResp To sTemp1
Showln sTemp1
Showln "Failed."
Procedure_Return
End
// 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/$entity",
// "id": "0-3A33FCEB9B74CC15!20344",
// "self": "https://graph.microsoft.com/v1.0/users/admin@chilkat.io/onenote/notebooks/0-3A33FCEB9B74CC15!20344",
// "createdDateTime": "2020-10-22T21:59:03.137Z",
// "displayName": "Testing Notebook",
// "lastModifiedDateTime": "2020-10-22T21:59:03.137Z",
// "isDefault": false,
// "userRole": "Owner",
// "isShared": false,
// "sectionsUrl": "https://graph.microsoft.com/v1.0/users/admin@chilkat.io/onenote/notebooks/0-3A33FCEB9B74CC15!20344/sections",
// "sectionGroupsUrl": "https://graph.microsoft.com/v1.0/users/admin@chilkat.io/onenote/notebooks/0-3A33FCEB9B74CC15!20344/sectionGroups",
// "createdBy": {
// "user": {
// "id": "4193973766868700757",
// "displayName": "Joe Smith"
// }
// },
// "lastModifiedBy": {
// "user": {
// "id": "4193973766868700757",
// "displayName": "Joe Smith"
// }
// },
// "links": {
// "oneNoteClientUrl": {
// "href": "onenote:https://d.docs.live.net/3a33fceb9b74cc15/Documents/Testing%20Notebook"
// },
// "oneNoteWebUrl": {
// "href": "https://onedrive.live.com/redir.aspx?cid=3a33fceb9b74cc15&page=edit&resid=3A33FCEB9B74CC15!20344"
// }
// }
// }
// Sample code for parsing the JSON response...
// Use the following online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
Get ComStringOf Of hoJResp '"@odata.context"' To sOdata_context
Get ComStringOf Of hoJResp "id" To sId
Get ComStringOf Of hoJResp "self" To sSelf
Get ComStringOf Of hoJResp "createdDateTime" To sCreatedDateTime
Get ComStringOf Of hoJResp "displayName" To sDisplayName
Get ComStringOf Of hoJResp "lastModifiedDateTime" To sLastModifiedDateTime
Get ComBoolOf Of hoJResp "isDefault" To iIsDefault
Get ComStringOf Of hoJResp "userRole" To sUserRole
Get ComBoolOf Of hoJResp "isShared" To iIsShared
Get ComStringOf Of hoJResp "sectionsUrl" To sSectionsUrl
Get ComStringOf Of hoJResp "sectionGroupsUrl" To sSectionGroupsUrl
Get ComStringOf Of hoJResp "createdBy.user.id" To sCreatedByUserId
Get ComStringOf Of hoJResp "createdBy.user.displayName" To sCreatedByUserDisplayName
Get ComStringOf Of hoJResp "lastModifiedBy.user.id" To sLastModifiedByUserId
Get ComStringOf Of hoJResp "lastModifiedBy.user.displayName" To sLastModifiedByUserDisplayName
Get ComStringOf Of hoJResp "links.oneNoteClientUrl.href" To sLinksOneNoteClientUrlHref
Get ComStringOf Of hoJResp "links.oneNoteWebUrl.href" To sLinksOneNoteWebUrlHref
End_Procedure