Table of contents
- General
- Power Automate samples
- Office 365 Users
- Count all users in tenant
- Order user response by displayName
- Filter for users with department XYZ
- Office 365 Groups
- Read all members of a group
- Count all members of a group
- Microsoft Teams
- Send a plain message in a chat
- Send a card (not adaptive card) in a chat
- Power Apps samples
- Read all members of a group
General
All actions that are send with these built-in actions are automatically delegated. This means, that the flow acts in your context and checks if you have permissions to read or write the data you requested. Consider the HTTP request actions as additional options, as you can do most things with the built in actions.
Here is an overview of the endpoints you can use:
Category | Endpoint Url | Links |
Users | https://graph.microsoft.com/v1.0/users
https://graph.microsoft.com/v1.0/me
2nd segment: messages, mailFolders, events, calendar, calendars, outlook, inferenceClassification | |
Groups | https://graph.microsoft.com/v1.0/groups | |
Teams | https://graph.microsoft.com/v.1.0/teams
https://graph.microsoft.com/v.1.0/me/chats
https://graph.microsoft.com/v.1.0/users
2nd segment: channels, chats, installedApps, messages, pinnedMessages | |
Outlook | https://graph.microsoft.com/v.1.0/me
https://graph.microsoft.com/v.1.0/users
2nd segment: messages,mailFolders,events,calendar,calendars,outlook,inferenceClassification |
Currently, not all oData query parameters are supported. If you need the full range of parameters, you have to use the HTTP premium connector and the Graph API.
Respect the limits for the Graph API and the respective service connector, for example Teams: https://learn.microsoft.com/en-us/graph/throttling-limits#microsoft-teams-service-limits or here https://learn.microsoft.com/en-us/connectors/teams
By default, all requests have a response limit of 100 items. If you want more, you can use top=999 to get up to 999 items. This is the max amount. Otherwise, you will have to process the odatanextlink to get more than 999 items.
Power Automate samples
For all requests where you use $orderby, $filter or $count, you have to to use a custom header (paste as is into the parameter)
ConsistencyLevel: eventual
Office 365 Users
Count all users in tenant
Method: GET
Content-Type: application/json
Custom Header 1: ConsistencyLevel: eventual
Uri:https://graph.microsoft.com/v1.0/users/$count
Order user response by displayName
Method: GET
Content-Type: application/json
Custom Header 1: ConsistencyLevel: eventual
Uri:https://graph.microsoft.com/v1.0/users?$orderby=displayName
Filter for users with department XYZ
Also works for jobTitle
Does not work for location or company.
Method: GET
Content-Type: application/json
Custom Header 1: ConsistencyLevel: eventual
Uri: https://graph.microsoft.com/v1.0/users?$select=displayName,companyName,department,mail,id,jobTitle&$filter=Department eq 'IT'
Office 365 Groups
Read all members of a group
Method: GET
Content-Type: application/json
Uri:https://graph.microsoft.com/v1.0/groups/Group-Id/members?$select=displayName,companyName,department,mail,id
Count all members of a group
Method: GET
Content-Type: application/json
Custom Header 1: ConsistencyLevel: eventual
Uri: https://graph.microsoft.com/v1.0/groups/group-id/members/$count
Microsoft Teams
Send a plain message in a chat
If you need to send a large number of messages in a short time, you should use this HTTP request as it has a throughput of 200 messages per second instead of 25 per 300 seconds with the built-in action (At least how I understand the documentation, though I have tested this with 500 message).
You can use the create chat built-in action to create a new chat, which will give you the conversation-id.
Method: POST
Content-Type: application/json
Uri: https://graph.microsoft.com/v1.0/me/chats/CONVERSATION-ID/messages
Body:
{
"body": {
"content": "Hello world"
}
}
Send a card (not adaptive card) in a chat
You can use the create chat built-in action to create a new chat, which will give you the conversation-id. The number “74d20c7f34aa4a7fb74e2b30004247c5” needs to be a randomly generated id. You can use a compose action with the expression guid() to get a random GUID string. The number needs to be the same in the body/content and attachments/id.
Method: POST
Content-Type: application/json
Uri: https://graph.microsoft.com/v1.0/me/chats/CONVERSATION-ID/messages
Body:
{
"subject": null,
"body": {
"contentType": "html",
"content": "<attachment id=\"74d20c7f34aa4a7fb74e2b30004247c5\"></attachment>"
},
"attachments": [
{
"id": "74d20c7f34aa4a7fb74e2b30004247c5",
"contentType": "application/vnd.microsoft.card.thumbnail",
"contentUrl": null,
"content": "{\r\n \"title\": \"This is an example of posting a card\",\r\n \"subtitle\": \"<h3>This is the subtitle</h3>\",\r\n \"text\": \"Here is some body text. <br>\\r\\nAnd a <a href=\\\"http://microsoft.com/\\\">hyperlink</a>. <br>\\r\\nAnd below that is some buttons:\",\r\n \"buttons\": [\r\n {\r\n \"type\": \"messageBack\",\r\n \"title\": \"Login to FakeBot\",\r\n \"text\": \"login\",\r\n \"displayText\": \"login\",\r\n \"value\": \"login\"\r\n }\r\n ]\r\n}",
"name": null,
"thumbnailUrl": null
}
]
}
Power Apps samples
You can obviously use built-in connectors for the respective connectors, the HTTP requests allow you to change specific things like selecting columns for the response.
Read all members of a group
Power Apps currently does not really understand the response of HTTP requests. Therefore, you have to basically parse the answer. You first have to set the result to variable and from there collect it into a collection.
You can only read a maximum of 999 members per group.
Set(
grpMembers,
Office365Groups.HttpRequestV2(
"https://graph.microsoft.com/v1.0/groups/Group-Id/members?$select=displayName,companyName,department,mail,id&$top=999",
"GET",
"",
//Technically the content type does not matter. It is not parsed in any way
{ContentType: "application/json"}
)
);
ClearCollect(
colMembers,
ForAll(
Table(grpMembers.value),
{
DisplayName: Text(Value.displayName),
Company:Text(Value.companyName),
Department: Text(Value.department),
Mail:Text(Value.mail),
Id:Text(Value.id)
}
)
)
Sadly, the code below is not possible, yet. Currently, Power Apps does not forward all headers to the request, which means that you cannot use clauses like: order by, filter by or count.
Office365Groups.HttpRequest(
"https://graph.microsoft.com/v1.0/groups/groupId/members?$select=displayName,companyName,department,mail,id&$orderby=DisplayName",
"GET",
"",
{ContentType: "application/json",ConsistencyLevel:"eventual"}
)
Thanks for reading! 💕