I am using Azure Logic App to post a message and call to MS Teams. I can add single user in Teams using the Microsoft learn guide. Now I am trying to add multiple users using the same logic.I found one post that it's possible using array object and then looping it but there are no details in there that I know how to use.
POST https://graph.microsoft.com/v1.0/teams/ece6f0a1-7ca4-498b-be79-edf6c8fc4d82/channels/19%3ALpxShHZZh9utjNcEmUS5aOEP9ASw85OUn05NcWYAhX81%40thread.tacv2/members Content-type: application/json
{ "@odata.type": "#microsoft.graph.aadUserConversationMember", "roles": [], "user@odata.bind": "https://graph.microsoft.com/v1.0/users('jacob@contoso.com')" }
https://learn.microsoft.com/en-us/graph/api/channel-post-members?view=graph-rest-1.0&tabs=http
I tried to create a Initialize Variable with Array type and value of
[ "user1@mscom" "user2@mscom" ]
then setting up For Each with variables('ChannelUsers')
and adding
{ "@odata.type": "#microsoft.graph.aadUserConversationMember", "roles": [], "user@odata.bind": "https://graph.microsoft.com/v1.0/users('items('For_each')')" }
but ending up with an error - Action For each must be a parent foreach scope of Scope "Add_Member" to be referenced by repeatItems or Items functions.
When you initialize the array variable, the array items must be separated by commas:
Then use the For each
loop over @variables('ChannelUsers')
:
Within the loop, you can use the HTTP method with the current item from the For each
loop: @{items('For_each')}
Result:
Here's a full code of the (slightly modified) Logic App: https://www.coderstool.com/cs/vJQJ7C