cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
torbenbj
Advocate I
Advocate I

Add user to group with graph

I have a solution where I add a user to a group with Power Automate with an APP that´s registered in Azure.

 

Works fine:

uri : https://graph.windows.net/@{variables('TenantId')}/groups/@{variables('SelectedGroupId')}/$links/mem...

body: 

{
"url": "https://graph.windows.net/@{variables('TenantId')}/directoryObjects/@{variables('UserId')}"
}

 

But I want to change to connect to graph.microsoft.com - that´s the challange:

 

I have used:

URI: https://graph.microsoft.com/@{variables('TenantId')}/groups/@{variables('SelectedGroupId')}/$li...

 

Body:

{
"url": "https://graph.microsoft.com/@{variables('TenantId')}/directoryObjects/@{variables('UserId')}"
}

 

When I run the flow I got following error:

"Invalid version."

 

I don´t where to search for the right information to put in?

 

Br

Torben

 

 

4 REPLIES 4
ChrisPiasecki
Super User
Super User

Hi @torbenbj,

 

You need to do a POST request to https://graph.microsoft.com/v1.0/groups/{group-id}/members/

 

More info here.

 

You can use the HTTP action where it will allow you to specify all the Azure AD OAuth2 authentication parameters. An example of how to do this is described here.

 

---
Please click Accept as Solution if my post answered your question. This will help others find solutions to similar questions. If you like my post and/or find it helpful, please consider giving it a Thumbs Up.

Hi Chris,

 

Thank you very much.

 

I don´t really know what I´m doing wrong...

 

Here is what I did:

torbenbj_1-1623049041006.png

continue to get this error:

torbenbj_2-1623049072305.png

 

BR

Torben

Hi @torbenbj,

 

At first glance it looks correct to me. The error is pretty vague and doesn't seem to indicate which input parameter its complaining about.

 

On your HTTP action can you "peek code" to see if the raw json looks valid (you can copy/paste the json into a JSON validator that you can find on google) 

 

Alternatively, can you try hard coding all your input values instead of using variabled and just put an empty Json {} in the body to see if you get past the initial error? Then add the JSON body back with a hardcoded user ID and see if that's successful. If it is then start adding your input parameter variables back one at a time until you narrow it down.

 

---
Please click Accept as Solution if my post answered your question. This will help others find solutions to similar questions. If you like my post and/or find it helpful, please consider giving it a Thumbs Up.

OliverR-82
Continued Contributor
Continued Contributor

I know that this is an old topic but since it was never resolved and I was struggling with the same issue myself, I figured I would post my findings here in any case. Maybe it'll help someone else.

 

The problem lies with the content of the request body, and more specifically the at (@) sign. You need to escape it by just typing it twice. 

{
  "@@odata.id": "https://graph.microsoft.com/v1.0/directoryObjects/<your variable>"
}

Helpful resources

Announcements
Power Automate News & Announcements

Power Automate News & Announcements

Keep up to date with current events and community announcements in the Power Automate community.

Community Calls Conversations

Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Automate Community Blog

Power Automate Community Blog

Check out the latest Community Blog from the community!

Users online (5,260)