Created by Microsoft Corporation, 2017. Provided As-is without warranty. Trademarks mentioned here are the property of their owners.
The following aspects of the API are covered in this sample. You can find additional documentation at the links below.
- Log-in the user
- GET a user's OneNote pages
- POST simple HTML to a new OneNote QuickNotes page
- POST multi-part message with image data included in the request*
- POST page with a URL rendered as an image*
- POST page with HTML rendered as an image*
- POST page with a PDF file rendered and attached*
* Indicates documentation for multi-part POST requests to the OneNote API before its integration into the Microsoft Graph API. The documentation for the outlined request examples work as of the production of this sample, but be aware that changes may be upcoming.
Tools and Libraries you will need to download, install, and configure for your development environment.
The PHP sample runs on a web server. The client browser needs to be able to access the web server to complete the handshake. Make sure that you install the PHP files so that:
- The web server you're using is accessible from the Internet
- The web server has PHP installed, with the cURL package enabled
- You have a normal URL with hostname (not just an IP address) to use for the Redirect URL. If you run this from your own desktop, you'll need to modify your Hosts file (in C:\Windows\System32\drivers\etc for Windows machines and /private/etc for Macs) and map your local server IP address to a new domain name, as in the following example.
Accounts
- As the developer, you'll need to have a Microsoft account and get a client ID string so your app can authenticate with the Microsoft Azure AD v2.0 endpoint.
- As the user of the sample, you'll need a Microsoft account (Azure AD/Org ID or an MSA account) so the OneNote API can send the pages to your OneDrive.
After you've setup your web server described above,....
- Clone the Git repository to a folder on your local machine.
- Go to the Microsoft app registration page.
- It is highly recommended that you get your own client ID, secret and redirect URI. You can get your own client ID, client secret and redirect URI. here
- For local development, the sample uses http://localhost:8888/callback.php as a redirect URI. For production, you should change this to point to your application's domain on your hosted deployment. If the root deployment URL is https://onenoteapisamples.com, then specify https://onenoteapisamples.com/callback.php as the Redirect URL (as in the following example). This URL must exactly match the deployed redirect URL. The root domain name must be unique, so if you use one domain for testing and another for production, you'll need to register separate client ids and secrets for each domain.Specify API settings in the Microsoft Application Registration Portal
Note: Chrome and Firefox do not allow cookies to be set on localhost, and thus authentication will not work on these browsers during development if you choose to redirect to localhost.
- Replace the following placeholders in the callback.php and index.php files with the associated values from the App Settings page:
- Replace CLIENT_ID with the client ID value.
- Replace CLIENT_SECRET with the client secret value.
- Replace REDIRECT_URI_PATH with the value of the deployment root URL. The deployment root URL consists of "http://" plus the root domain URL, so if your redirect URL looks like http://onenoteapisamples.com/callback.php, the deployment root URL is "http://onenoteapisamples.com." At run time, the redirect URL value will resolve to "http://onenoteapisamples.com/callback.php."
- Put the sample files in the root directory on your web server.
- Open a browser and navigate to the default .php page.
- Login using your Microsoft account, and allow the app to create pages in your OneNote notebooks.
Date | Change |
---|---|
May 2017 | Updated to utilize the Microsoft Graph v1.0 base URL for OneNote resources |
April 2017 | Updated to utilize the Microsoft Graph API endpoints. |
May 2014 | Initial public release for this code sample. |
- If you're running the sample on a web server on a home network, and you don't have a fixed IP address and assigned domain name, you may need to use a DDNS provider, and then forward the HTTP/S ports to your local server.
- The PHP files in this sample contain CRLF line endings. You'll need to retain these line endings when you open and edit these files in your editor. See Dealing with line endings for guidance on how to retain CRLF line endings on all platforms.
- Visit the dev.onenote.com Dev Center
- Contact us on StackOverflow (tagged OneNote)
- Follow us on Twitter @onenotedev
- Read our OneNote Developer blog
- Explore the API using the Graph Explorer
- API Reference documentation
- Known Issues
- Getting Started with the Microsoft Graph API
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.