Hers Crp
@ Vinodh Narayanan Apr 03, 2019 431k 4 Oo
CalendarEvents.zip
In my previous articles, | have written about site collection, user properties, fetching access
tokens, retrieving and sending emails, and lots more, | have added the links below for your
reference. Please go through these before following the steps given in this article.
* HowTo 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 Pr sing Microsoft Graph API
# Retrieve site collections and g Microsoft Graph API
e Retrieve Mailbox Folders Usi Graph API
Retrieve Events From The Calenua:
°f users/{{userid}}/events
ou office 365 calendar
Testec DN data like below. In this article, we are going
to retr
hetps:/,
[email protected]/events
261
G cemtwesmnnareecinente.comiroe. cn eves",
308Step 1-Fetch Access Token
AuthUrl: https://login.microsoftonline.com/{{tenant}}/oauth2/v2.0/token
Type: POST
01. | var token; // Initialize Globally
02. | function requestToken() {
3. $.ajax({
4. async": true,
8. Domain": true,
6. “https: //howling-crypt-
47129 .herokuapp..com/https:: //login.microsoftonline.com/sharepointtechie.c
07. method": "POST",
08. "headers": {
09. “content-type": “application/x-www-form-urlencoded™
10. b
11. "data": {
12. "grant_type lient_credentials",
13. "client_id ba 0301 -27df -44b1-b4fe-
7911b9a918de", //Provide your app id
14. lient_secret -Z760VPNO39W1WPoAp+1aICq66vs70UtE41hDQYWx¢
1s. “scope “: “https: //graph.microsoft.com/.default”
16. b
17. success: function(response) {
18. log(response);
19. token = response.access_token; //Store the token into global
20. 2
21. error: function(error) {
22. log(JSON. stringify(error)) 5
23. }
24. »
2s. |}
The successful response is shown below.
EndPointCode
e1.
2.
03.
ea.
es.
26.
7.
28.
29.
10.
1.
12.
13.
14.
15.
16.
17.
function RetrieveCalendarEvents() {
$-ajax({
method: ‘GET’,
url: “https: //graph.microsoft.com/v1.@/users/vinodhvignesh@share
headers: {
‘authorization’: "Bearer ' + token,
‘Content-Type’: ‘application/json'
hb
success: function(response) {
var data = response. value;
data.map(function(events) {
$(‘#display').append('
StartDate: ' + events.start.dz
EndDate: ' + events.end.dateTime + '
Subject: ' + events.subject + '')3
y)
b
error: function(error) {},
»
HTTP "200", success ~- it returns the JSON data Below,
\sovata. context: ~netps://grapn.n.crosort. com vi.t/smetacatamusers{ vanoanvagnesnasusnarepo..
wyvalue: Anray(7)
\/"c3CoyH¥ws@6OSDONNrHOOQACFBYOXQ==""
(/"cCoyHHws@COSDONNHOOQABXYCXIAR=""
“w/cacoyarsecosvonnrhoogABRyexrg:
<3 Cay @GOSDOMNPROOQABS Vg
'c3CoyHHs@GOSOONPHOOQABBVihiQe="
/"eACoyHHusecoS0ONNrHOOOAAYFEZTO=="
"W/" caCoynts@GOSDONNPHOOYAAE FETA
4d
id:
aa:
jeer
"AAMKAD?NTKxOWYLAUZHOGENG..
"AANKAD? INTKxOWyLAUZNOQENE
+ (gedat
+ {oda
{aedata
+ (Godata.etag:
‘
id:
4“
"AAMKADTINTK OW LAUZHOQENG..
"AAMKADLNTK SONY LAUZHOQENG..
"AAMKADINTKXOWYYLAUZHOQENG..
Then, apply .map to iterate over the JSON data and display it on the page.
Full Code
01. |