英文:
Get Calendar Events of all group members via Power Automate
问题
我想通过Power Automate获取组织/团队中所有成员的日历事件。目前,我看到的“获取日历(V2)”和“获取事件的日历视图(V3)”只返回用户自己的相应值(拥有该流的用户)。我想知道是否有办法获取组成员的日历事件,考虑到他们已经授予了与组织成员共享所有日历数据的相应权限。
对此的任何帮助将不胜感激。
谢谢!
英文:
I want to get the Calendar Events of all of the members in the organization/team via Power Automate. As I see now the "Get Calendars (V2)" and the "Get Calendar View of Events (V3)" only return the corresponding values of the user itself (the one who owns the flow). I was wondering if there's a way to get the calendar events of the group members given the fact that they've given the corresponding permission to share all the calendar data with the organization members.
Any help on this will be much appreciated.
Thanks!
答案1
得分: 0
内置连接器将使用当前用户。
我不认为你可以以这种方式模拟用户。
最佳方法或替代方法是使用带有服务帐户的Graph API(Azure AD应用程序注册)。您可以获取任何人的事件,因此可以获取组中的每个用户的事件。
获取/用户/{id | userPrincipalName}/日历/事件
获取/组/{id}/成员
要使用Power Automate调用Graph API,您需要HTTP连接器(这是高级连接器,必须为您的环境启用连接器)
您必须在Azure AD(或Microsoft Entra)中声明一个服务帐户:
-
创建新的应用程序注册(应用程序>应用程序注册)
- 复制客户端ID
- 复制租户ID
-
添加以下权限(应用程序>应用程序注册>API权限)
- Graph API>应用程序>Calendars.Read.All
- Graph API>应用程序>Directory.Read.All
- Graph API>应用程序>GroupMember.Read.All
-
授予权限的管理员同意
-
生成客户端密钥(应用程序>应用程序注册>证书和密钥>客户端密钥)
在Power Automate中,创建一个新的云流程,例如带有组ID作为输入的按钮。
声明变量:
- 应用程序注册上的客户端ID
- 应用程序注册上的客户端密钥
- 租户ID
- 用于存储所有事件的数组
接下来,使用通用HTTP连接器调用Graph API以获取组成员
方法:GET
URI:https://graph.microsoft.com/v1.0/groups/<输入的组ID>/members
标头:Content-Type application/json
标头:接受应用程序/JSON
身份验证:Active Directory OAuth
租户:您的租户ID变量
受众:https://graph.microsoft.com
客户端ID:您的客户端ID变量
凭据类型:密钥
密钥:您的客户端密钥变量
将结果转换为JSON,使用以下架构:
{
"type": "object",
"properties": {
"@@odata.context": {
"type": "string"
},
"value": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"mail": {
"type": "string"
}
},
"required": [
"id",
"mail"
]
}
}
}
}
对于每个成员,调用Graph API以获取用户的事件
方法:GET
URI:https://graph.microsoft.com/v1.0/users/<JSON foreach中的用户ID>/事件
标头:Content-Type application/json
标头:接受应用程序/JSON
身份验证:Active Directory OAuth
租户:您的租户ID变量
受众:https://graph.microsoft.com
客户端ID:您的客户端ID变量
凭据类型:密钥
密钥:您的客户端密钥变量
将结果转换为JSON,使用以下架构:
{
"type": "object",
"properties": {
"@@odata.context": {
"type": "string"
},
"value": {
"type": "array",
"items": {
"type": "object",
"properties": {
"@@odata.etag": {
"type": "string"
},
"id": {
"type": "string"
},
"createdDateTime": {
"type": "string"
},
"lastModifiedDateTime": {
"type": "string"
},
"changeKey": {
"type": "string"
},
"categories": {
"type": "array"
},
"transactionId": {
"type": "string"
},
"originalStartTimeZone": {
"type": "string"
},
"originalEndTimeZone": {
"type": "string"
},
"iCalUId": {
"type": "string"
},
"reminderMinutesBeforeStart": {
"type": "integer"
},
"isReminderOn": {
"type": "boolean"
},
"hasAttachments": {
"type": "boolean"
},
"subject": {
"type": "string"
},
"bodyPreview": {
"type": "string"
},
"importance": {
"type": "string"
},
"sensitivity": {
"type": "string"
},
"isAllDay": {
"type": "boolean"
},
"isCancelled": {
"type": "boolean"
},
"isOrganizer": {
"type": "boolean"
},
"responseRequested": {
"type": "boolean"
},
"seriesMasterId": {},
"showAs": {
"type": "string"
},
"type": {
"type": "string"
},
"webLink": {
"type": "string"
},
"onlineMeetingUrl": {},
"isOnlineMeeting": {
"type": "boolean"
},
"onlineMeetingProvider": {
"type": "string"
},
"allowNewTimeProposals": {
"type": "boolean"
},
"occurrenceId": {},
"isDraft": {
"type": "boolean"
},
"hideAttendees": {
"type": "boolean"
},
"responseStatus": {
"type": "object",
"properties": {
"response": {
"type": "string"
},
"time": {
"type": "string"
}
}
},
"body": {
"type": "object",
"properties": {
"contentType": {
"type": "string"
},
"content": {
"type": "string"
}
}
},
"start": {
"type": "object",
"properties": {
"dateTime": {
"type": "string"
},
"timeZone": {
"type": "string"
}
}
},
"end": {
"type": "object",
"properties": {
"dateTime": {
"type": "string"
},
"timeZone": {
"type": "string"
}
}
英文:
The built-in connector will use the current user.
I don't think you can impersonate a user this way.
The best approach or alternative is to use Graph API with a servcie account (Azure AD app registration). You can get events from anyone, so from each users part of a group.
GET /users/{id | userPrincipalName}/calendar/events
GET /groups/{id}/members
To call Graph API with Power Automate you will need HTTP connector (it's a premium connector and the connector must be enable for your environment)
You have to declare a service account in Azure AD (or Microsoft Entra):
- Create a new app registration (Applications > App registrations)
- Copy the client id
- Copy the tenant id
- Add the following permissions (Applications > App registrations > API permissions)
- Graph API > Application > Calendars.Read.All
- Graph API > Application > Directory.Read.All
- Graph API > Application > GroupMember.Read.All
- Grant admin consent for the permissions
- Generate a client secret (Applications > App registrations > Certificate & secrets > Client secrets)
In Power Automate, create a new cloud flow, for example a button with the group id as input.
Declare variables:
- Client ID on the app registration
- Client secret for the app registration
- Tenant ID
- Array to store all the events
Next, call Graph API to get group members with the generic HTTP connector
Method: GET
URI: https://graph.microsoft.com/v1.0/groups/<your group id input>/members
Headers: Content-Type application/json
Headers: Accept application/json
Authentication: Active Directory OAuth
Tenant: your tenant id variable
Audience: https://graph.microsoft.com
Client ID: your client id variable
Crendential Type: Secret
Secret: your client secret variable
Transform the result in JSON using the schema:
{
"type": "object",
"properties": {
"@@odata.context": {
"type": "string"
},
"value": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"mail": {
"type": "string"
}
},
"required": [
"id",
"mail"
]
}
}
}
}
For each members, call Graph API to get user's events
Method: GET
URI: https://graph.microsoft.com/v1.0/users/<user id fron json foreach>/event
Headers: Content-Type application/json
Headers: Accept application/json
Authentication: Active Directory OAuth
Tenant: your tenant id variable
Audience: https://graph.microsoft.com
Client ID: your client id variable
Crendential Type: Secret
Secret: your client secret variable
Transform the result in JSON using the schema:
{
"type": "object",
"properties": {
"@@odata.context": {
"type": "string"
},
"value": {
"type": "array",
"items": {
"type": "object",
"properties": {
"@@odata.etag": {
"type": "string"
},
"id": {
"type": "string"
},
"createdDateTime": {
"type": "string"
},
"lastModifiedDateTime": {
"type": "string"
},
"changeKey": {
"type": "string"
},
"categories": {
"type": "array"
},
"transactionId": {
"type": "string"
},
"originalStartTimeZone": {
"type": "string"
},
"originalEndTimeZone": {
"type": "string"
},
"iCalUId": {
"type": "string"
},
"reminderMinutesBeforeStart": {
"type": "integer"
},
"isReminderOn": {
"type": "boolean"
},
"hasAttachments": {
"type": "boolean"
},
"subject": {
"type": "string"
},
"bodyPreview": {
"type": "string"
},
"importance": {
"type": "string"
},
"sensitivity": {
"type": "string"
},
"isAllDay": {
"type": "boolean"
},
"isCancelled": {
"type": "boolean"
},
"isOrganizer": {
"type": "boolean"
},
"responseRequested": {
"type": "boolean"
},
"seriesMasterId": {},
"showAs": {
"type": "string"
},
"type": {
"type": "string"
},
"webLink": {
"type": "string"
},
"onlineMeetingUrl": {},
"isOnlineMeeting": {
"type": "boolean"
},
"onlineMeetingProvider": {
"type": "string"
},
"allowNewTimeProposals": {
"type": "boolean"
},
"occurrenceId": {},
"isDraft": {
"type": "boolean"
},
"hideAttendees": {
"type": "boolean"
},
"responseStatus": {
"type": "object",
"properties": {
"response": {
"type": "string"
},
"time": {
"type": "string"
}
}
},
"body": {
"type": "object",
"properties": {
"contentType": {
"type": "string"
},
"content": {
"type": "string"
}
}
},
"start": {
"type": "object",
"properties": {
"dateTime": {
"type": "string"
},
"timeZone": {
"type": "string"
}
}
},
"end": {
"type": "object",
"properties": {
"dateTime": {
"type": "string"
},
"timeZone": {
"type": "string"
}
}
},
"location": {
"type": "object",
"properties": {
"displayName": {
"type": "string"
},
"locationType": {
"type": "string"
},
"uniqueIdType": {
"type": "string"
},
"address": {
"type": "object",
"properties": {}
},
"coordinates": {
"type": "object",
"properties": {}
}
}
},
"locations": {
"type": "array"
},
"recurrence": {},
"attendees": {
"type": "array"
},
"organizer": {
"type": "object",
"properties": {
"emailAddress": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"address": {
"type": "string"
}
}
}
}
},
"onlineMeeting": {},
"calendar@odata.associationLink": {
"type": "string"
},
"calendar@odata.navigationLink": {
"type": "string"
}
},
"required": [
"@@odata.etag",
"id",
"createdDateTime",
"lastModifiedDateTime",
"changeKey",
"categories",
"transactionId",
"originalStartTimeZone",
"originalEndTimeZone",
"iCalUId",
"reminderMinutesBeforeStart",
"isReminderOn",
"hasAttachments",
"subject",
"bodyPreview",
"importance",
"sensitivity",
"isAllDay",
"isCancelled",
"isOrganizer",
"responseRequested",
"seriesMasterId",
"showAs",
"type",
"webLink",
"onlineMeetingUrl",
"isOnlineMeeting",
"onlineMeetingProvider",
"allowNewTimeProposals",
"occurrenceId",
"isDraft",
"hideAttendees",
"responseStatus",
"body",
"start",
"end",
"location",
"locations",
"recurrence",
"attendees",
"organizer",
"onlineMeeting",
"calendar@odata.associationLink",
"calendar@odata.navigationLink"
]
}
}
}
}
Activate and start the flow with a group id as input:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论