- How To Fetch Access Token
- Getting User Properties From Office 365 Using Microsoft Graph API
- Send Email Using Microsoft Graph API From SharePoint Online
- Upload And Set Office 365 Profile Image Using Microsoft Graph API
- Retrieve site collections and subsites using Microsoft Graph API
- Retrieve Mailbox Folders Using Microsoft Graph API
- EndPoint - https://graph.microsoft.com/v1.0/users/{{userid}}/events
- Usage - It retrieves all events of the user from office 365 calendar
Please follow my previous article, How to fetch access token, to authenticate your web application to fetch the access token and authenticate.
Step 1 - Fetch Access Token
AuthUrl: https://login.microsoftonline.com/{{tenant}}/oauth2/v2.0/token
- var token; // Initialize Globally
- function requestToken() {
- $.ajax({
- "async": true,
- "crossDomain": true,
- "url": "https://howling-crypt-47129.herokuapp.com/https://login.microsoftonline.com/sharepointtechie.onmicrosoft.com/oauth2/v2.0/token", // Pass your tenant name instead of sharepointtechie
- "method": "POST",
- "headers": {
- "content-type": "application/x-www-form-urlencoded"
- },
- "data": {
- "grant_type": "client_credentials",
- "client_id ": "8baf0301-27df-44b1-b4fe-7911b9a918de", //Provide your app id
- "client_secret": "tZ76oVPN039WlWPoAp+1aICq66vs7oUtE4lhDQYwxGY=", //Provide your secret
- "scope ": "https://graph.microsoft.com/.default"
- },
- success: function(response) {
- log(response);
- token = response.access_token; //Store the token into global variable
- },
- error: function(error) {
- log(JSON.stringify(error));
- }
- })
- }

Method
Code
- function RetrieveCalendarEvents() {
- $.ajax({
- method: 'GET',
- url: "https://graph.microsoft.com/v1.0/users/[email protected]/events",
- headers: {
- 'Authorization': 'Bearer ' + token,
- 'Content-Type': 'application/json'
- },
- success: function(response) {
- var data = response.value;
- data.map(function(events) {
- $('#display').append('<li>StartDate: ' + events.start.dateTime + ' </br></br> EndDate: ' + events.end.dateTime + ' </br></br> Subject: ' + events.subject + '</li></br></br>');
- })
- },
- error: function(error) {},
- })
- }
- <script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.3.1.min.js"></script>
- <script type="text/javascript">
- var token;
- $(document).ready(function() {
- requestToken();
- });
- function requestToken() {
- $.ajax({
- "async": true,
- "crossDomain": true,
- "url": "https://howling-crypt-47129.herokuapp.com/https://login.microsoftonline.com/sharepointtechie.onmicrosoft.com/oauth2/v2.0/token", // Pass your tenant name instead of sharepointtechie
- "method": "POST",
- "headers": {
- "content-type": "application/x-www-form-urlencoded"
- },
- "data": {
- "grant_type": "client_credentials",
- "client_id ": "8baf0301-27df-44b1-b4fe-7911b9a918de", //Provide your app id
- "client_secret": "tZ76oVPN039WlWPoAp+1aICq66vs7oUtE4lhDQYwxGY=", //Provide your secret
- "scope ": "https://graph.microsoft.com/.default"
- },
- success: function(response) {
- console.log(response);
- token = response.access_token;
- // console.log(token);
- RetrieveCalendarEvents();
- },
- error: function(error) {
- console.log(JSON.stringify(error));
- }
- })
- }
- function RetrieveCalendarEvents() {
- $.ajax({
- method: 'GET',
- url: "https://graph.microsoft.com/v1.0/users/[email protected]/events",
- headers: {
- 'Authorization': 'Bearer ' + token,
- 'Content-Type': 'application/json'
- },
- success: function(response) {
- var data = response.value;
- console.log(response);
- data.map(function(events) {
- $('#display').append('<li>StartDate: ' + events.start.dateTime + ' </br></br> EndDate: ' + events.end.dateTime + ' </br></br> Subject: ' + events.subject + '</li></br></br>');
- })
- },
- error: function(error) {
- },
- })
- }
The final result is shown on the screen below. I have printed some basic infomation to HTML.



kamo epPosted Mar 3, 2021, 12:51 PM EST
Hi Vinodh thank you for sharing your code exemple, i did same way as you, declared token in global scope and assigned fetched acces_token to it inside function, when i log it out of function scope it's undefined could you help my please?
Ahmad IhsanPosted Jun 16, 2020, 5:59 AM EDT
Hi, nice article. I have created 15 events on my outlook calendar but the API is returning only 10 events. Is this the limit? how can I get all events from the calendar?
Ryan TranPosted Oct 10, 2019, 6:57 PM EDT
I have problem with error: NoPermissionsInAccessToken though i added permission Calendar.ReadWrite