Forum Discussion
Create a Teams calendar event from a bot
Hi,
I have a nodejs bot running with my Teams app. I would link to add a new meeting event in Teams calendar, is it possible? I have read about 'schedules' in Graph API, but I am not sure if this is the key, since I can not see fields like startTime, duration, ...
Could you please help me?
Thanks in advance,
Diego
16 Replies
- Lewis-HIron ContributorGo to the Group you want the calendar for:
Click “Calendar”:
Copy the URL from your browser:
Add a new tab within a Channel in Teams:
Select “Website”:
Add a name and the URL you copied from the Outlook Web App:
Sign in to Microsoft when prompted. - Nikitha-MSFT
Microsoft
diegoSpace - Could you please try Graph API to create calendar event.
- diegoSpaceBrass Contributor
Nikitha-MSFT Thanks for your response.
I have some doubts, please correct what I write below if required:
As far as I understand, I can use Application permission to create an event, so I will access Graph without a user (https://docs.microsoft.com/en-us/graph/auth-v2-service)
I will use 'POST /users/{id}/events', where the {id} must be Teams userId (what I get in 'activity.from.id' of an incoming command), and not the Office365/Azure id.
'Bearer' header is required, so I need a token. I have running code to get Teams users, and previously I get a bearer token with this options:
var options = {
uri: 'https://login.microsoftonline.com/{tenant ID}/oauth2/v2.0/token',
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: 'client_id=' + {appId} + '&client_secret=' + {appPassword} + '&scope=https%3A%2F%2Fgraph.microsoft.com%2F.default&grant_type=client_credentials',
};With the token received in the response, I can access to the users in a Teams group:
https://graph.microsoft.com/v1.0/groups/{groupID}/membersCan I use this token (for my application) to create an event for a user from the bot?
With a userId = '29:184h5dKIrOfsVklZrZyWMe91Gio.....nNQiCqFNLreLIEq-YC' I have tried this PUT:
https://graph.microsoft.com/v1.0/users/{userId}/calendar/events
and the previous Authentication bearer token
with an example event as bodybut I get a '500 Internal Server Error' as response.
What am I doing wrong?
Thanks a lot,
Diego
- Nikitha-MSFT
Microsoft
diegoSpace - {id} should be user azure id or UPN. Could you please try using the azure id or UPN.