Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

DataFlex Web API Examples

Primary Categories

ABN AMRO
AWS Secrets Manager
AWS Security Token Service
AWS Translate
Activix CRM
Adyen
Alibaba Cloud OSS
Amazon Cognito
Amazon DynamoDB
Amazon MWS
Amazon Pay
Amazon Rekognition
Amazon SP-API
Amazon Voice ID
Aruba Fatturazione
Azure Maps
Azure Monitor
Azure OAuth2
Azure Storage Accounts
Backblaze S3
Banco Inter
Belgian eHealth Platform
Bitfinex v2 REST
Bluzone
BrickLink
Bunny CDN
CallRail
CardConnect
Cerved
ClickBank
Clickatell
Cloudfare
Constant Contact
DocuSign
Duo Auth MFA
ETrade
Ecwid
Egypt ITIDA
Egypt eReceipt
Etsy
Facebook
Faire
Frame.io
GeoOp
GetHarvest
Global Payments
Google People
Google Search Console
Google Translate
Google Vision
Hungary NAV Invoicing
IBM Text to Speech
Ibanity
IntakeQ
JCC Cyprus
Jira
Lightspeed
MYOB
Magento
Mailgun
Malaysia MyInvois

Mastercard
MedTunnel
MercadoLibre
MessageMedia
Microsoft Calendar
Microsoft Group
Microsoft Tasks and Plans
Microsoft Teams
Moody's
Okta OAuth/OIDC
OneLogin OIDC
OneNote
OpenAI ChatGPT
PRODA
PayPal
Paynow.pl
Peoplevox
Populi
QuickBooks
Rabobank
Refinitiv
Royal Mail OBA
SCiS Schools Catalogue
SII Chile
SMSAPI
SOAP finkok.com
Salesforce
SendGrid
Shippo
Shopify
Shopware
Shopware 6
SimpleTexting
Square
Stripe
SugarCRM
TicketBAI
TikTok Shop
Trello
Twilio
Twitter API v2
Twitter v1
UPS
UniPin
VoiceBase
Vonage
WaTrend
Walmart v3
Wasabi
WhatsApp
WiX
WooCommerce
WordPress
Xero
Yahoo Mail
Yapily
Yousign
ZATCA
Zendesk
Zoom
_Miscellaneous_
eBay
effectconnect
hacienda.go.cr

 

 

 

(DataFlex) OneNote - Create Page

Creates a new OneNote page with a rendered image and an attached PDF.

For more information, see https://docs.microsoft.com/en-us/graph/api/section-post-pages?view=graph-rest-1.0

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

Use ChilkatAx-win32.pkg

Procedure Test
    Handle hoHttp
    Boolean iSuccess
    Variant vReq
    Handle hoReq
    Handle hoSbHtml
    Boolean iBCrlf
    Handle hoDtNow
    Integer iNumReplaced
    Variant vBdPdf
    Handle hoBdPdf
    Variant vResp
    Handle hoResp
    Variant vSbResponseBody
    Handle hoSbResponseBody
    Handle hoJResp
    Integer iRespStatusCode
    String sOdata_context
    String sId
    String sSelf
    String sCreatedDateTime
    String sTitle
    String sCreatedByAppId
    String sContentUrl
    String sLastModifiedDateTime
    String sLinksOneNoteClientUrlHref
    String sLinksOneNoteWebUrlHref
    String sTemp1
    Integer iTemp1
    Boolean bTemp1

    // 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

    // To create a OneNote page, we want to send an HTTP request like the following:

    // POST https://graph.microsoft.com/v1.0/me/onenote/sections/{section_id}/pages
    // Content-length: 312
    // Content-type: multipart/form-data; boundary=MyPartBoundary198374
    // 
    // --MyPartBoundary198374
    // Content-Disposition:form-data; name="Presentation"
    // Content-Type:text/html
    // 
    // <!DOCTYPE html>
    // <html>
    //   <head>
    //     <title>A page with <i>rendered</i> images and an <b>attached</b> file</title>
    //     <meta name="created" content="2015-07-22T09:00:00-08:00" />
    //   </head>
    //   <body>
    //     <p>Here's an image from an online source:</p>
    //     <img src="https://..." alt="an image on the page" width="500" />
    //     <p>Here's an image uploaded as binary data:</p>
    //     <img src="name:imageBlock1" alt="an image on the page" width="300" />
    //     <p>Here's a file attachment:</p>
    //     <object data-attachment="FileName.pdf" data="name:fileBlock1" type="application/pdf" />
    //   </body>
    // </html>
    // 
    // --MyPartBoundary198374
    // Content-Disposition:form-data; name="imageBlock1"
    // Content-Type:image/jpeg
    // 
    // ... binary image data ...
    // 
    // --MyPartBoundary198374
    // Content-Disposition:form-data; name="fileBlock1"
    // Content-Type:application/pdf
    // 
    // ... binary file data ...
    // 
    // --MyPartBoundary198374--

    // Build the request in a Chilkat HTTP request object:
    Get Create (RefClass(cComChilkatHttpRequest)) To hoReq
    If (Not(IsComObjectCreated(hoReq))) Begin
        Send CreateComObject of hoReq
    End

    // Our URL is https://graph.microsoft.com/v1.0/me/onenote/sections/{section_id}/pages
    // The path part of the URL is "/v1.0/me/onenote/sections/{section_id}/pages"
    // In this example, our section ID is "0-3A33FCEB9B74CC15!20350"
    Set ComPath Of hoReq To "/v1.0/me/onenote/sections/0-3A33FCEB9B74CC15!20350/pages"

    // We'll be sending a POST.
    Set ComHttpVerb Of hoReq To "POST"

    // The Content-Type is multipart/form-data
    // Chilkat will automatically generate a boundary string.
    Set ComContentType Of hoReq To "multipart/form-data"

    // When Chilkat HTTP was written many years ago, multipart requests were primarily for uploads.
    // Thus the names of methods that add a multipart section end with "ForUpload".
    // The multipart request we wish to build has 3 sections: text/html, image/jpeg, and application/pdf.

    // ------------------------------
    // Add the text/html part.
    // ------------------------------
    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbHtml
    If (Not(IsComObjectCreated(hoSbHtml))) Begin
        Send CreateComObject of hoSbHtml
    End
    Move True To iBCrlf
    Get ComAppendLine Of hoSbHtml "<!DOCTYPE html>" iBCrlf To iSuccess
    Get ComAppendLine Of hoSbHtml "<html>" iBCrlf To iSuccess
    Get ComAppendLine Of hoSbHtml "  <head>" iBCrlf To iSuccess
    Get ComAppendLine Of hoSbHtml "    <title>A page with <i>rendered</i> images and an <b>attached</b> file</title>" iBCrlf To iSuccess
    Get ComAppendLine Of hoSbHtml '    <meta name="created" content="TIMESTAMP_CURRENT" />' iBCrlf To iSuccess
    Get ComAppendLine Of hoSbHtml "  </head>" iBCrlf To iSuccess
    Get ComAppendLine Of hoSbHtml "  <body>" iBCrlf To iSuccess
    Get ComAppendLine Of hoSbHtml "    <p>Here's an image from an online source:</p>" iBCrlf To iSuccess
    Get ComAppendLine Of hoSbHtml '    <img src="https://www.chilkatsoft.com/images/starfish.jpg" alt="an image on the page" width="500" />' iBCrlf To iSuccess
    Get ComAppendLine Of hoSbHtml "    <p>Here's an image uploaded as binary data:</p>" iBCrlf To iSuccess
    Get ComAppendLine Of hoSbHtml '    <img src="name:imageBlock1" alt="an image on the page" width="300" />' iBCrlf To iSuccess
    Get ComAppendLine Of hoSbHtml "    <p>Here's a file attachment:</p>" iBCrlf To iSuccess
    Get ComAppendLine Of hoSbHtml '    <object data-attachment="FileName.pdf" data="name:fileBlock1" type="application/pdf" />' iBCrlf To iSuccess
    Get ComAppendLine Of hoSbHtml "  </body>" iBCrlf To iSuccess
    Get ComAppendLine Of hoSbHtml "</html>" iBCrlf To iSuccess

    Get Create (RefClass(cComCkDateTime)) To hoDtNow
    If (Not(IsComObjectCreated(hoDtNow))) Begin
        Send CreateComObject of hoDtNow
    End
    Get ComSetFromCurrentSystemTime Of hoDtNow To iSuccess
    Get ComGetAsTimestamp Of hoDtNow True To sTemp1
    Get ComReplace Of hoSbHtml "TIMESTAMP_CURRENT" sTemp1 To iNumReplaced

    Get ComGetAsString Of hoSbHtml To sTemp1
    Get ComAddStringForUpload2 Of hoReq "Presentation" "" sTemp1 "utf-8" "text/html" To iSuccess

    // ------------------------------
    // Add the JPG image.
    // ------------------------------
    Get ComAddFileForUpload2 Of hoReq "imageBlock1" "qa_data/jpg/penguins2.jpg" "image/jpeg" To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoReq To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    // ------------------------------
    // Add the PDF attachment.
    // ------------------------------
    Get Create (RefClass(cComChilkatBinData)) To hoBdPdf
    If (Not(IsComObjectCreated(hoBdPdf))) Begin
        Send CreateComObject of hoBdPdf
    End
    Get ComLoadFile Of hoBdPdf "qa_data/pdf/helloWorld.pdf" To iSuccess
    If (iSuccess = False) Begin
        Showln "Failed to load PDF file."
        Procedure_Return
    End

    Get pvComObject of hoBdPdf to vBdPdf
    Get ComAddBdForUpload Of hoReq "fileBlock1" "FileName.pdf" vBdPdf "application/pdf" To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoReq To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    // Adds the "Authorization: Bearer ACCESS_TOKEN" header.
    Set ComAuthToken Of hoHttp To "ACCESS_TOKEN"

    // POST to https://graph.microsoft.com/v1.0/me/onenote/sections/{section_id}/pages
    // The path part of the URL is already specified in the req object.
    // We only need to specify the domain and the fact that we're doing "https" (SSL/TLS).
    Get pvComObject of hoReq to vReq
    Get ComSynchronousRequest Of hoHttp "graph.microsoft.com" 443 True vReq To vResp
    If (IsComObject(vResp)) Begin
        Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
        Set pvComObject Of hoResp To vResp
    End
    Get ComLastMethodSuccess Of hoHttp To bTemp1
    If (bTemp1 = 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

    Get ComStatusCode Of hoResp To iTemp1
    Showln "Response status code: " iTemp1
    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."
        Send Destroy of hoResp
        Procedure_Return
    End

    Send Destroy of hoResp

    // 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/sections('0-3A33FCEB9B74CC15%2120350')/pages/$entity",
    //   "id": "0-18ac61117a664f7e946bcceaeebd6f57!36-3A33FCEB9B74CC15!20350",
    //   "self": "https://graph.microsoft.com/v1.0/users/admin@chilkat.io/onenote/pages/0-18ac61117a664f7e946bcceaeebd6f57!36-3A33FCEB9B74CC15!20350",
    //   "createdDateTime": "2020-10-22T19:02:12Z",
    //   "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-18ac61117a664f7e946bcceaeebd6f57!36-3A33FCEB9B74CC15!20350/content",
    //   "lastModifiedDateTime": "2020-10-23T00:02:13.3254289Z",
    //   "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=9d78c221-486e-45f8-8355-1810e475f6c0&page-id=36cd1982-1ef1-4b11-b5a1-30b3dbc43d05&end"
    //     },
    //     "oneNoteWebUrl": {
    //       "href": "https://onedrive.live.com/redir.aspx?cid=3a33fceb9b74cc15&page=edit&resid=3A33FCEB9B74CC15!20344&parId=3A33FCEB9B74CC15!187&wd=target%28Ddd.one%7C9d78c221-486e-45f8-8355-1810e475f6c0%2FA%20page%20with%20rendered%20images%20and%20an%20attached%20file%7C36cd1982-1ef1-4b11-b5a1-30b3dbc43d05%2F%29"
    //     }
    //   }
    // }

    // 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 "title" To sTitle
    Get ComStringOf Of hoJResp "createdByAppId" To sCreatedByAppId
    Get ComStringOf Of hoJResp "contentUrl" To sContentUrl
    Get ComStringOf Of hoJResp "lastModifiedDateTime" To sLastModifiedDateTime
    Get ComStringOf Of hoJResp "links.oneNoteClientUrl.href" To sLinksOneNoteClientUrlHref
    Get ComStringOf Of hoJResp "links.oneNoteWebUrl.href" To sLinksOneNoteWebUrlHref


End_Procedure

 

© 2000-2024 Chilkat Software, Inc. All Rights Reserved.