cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
torbenbj
Helper I
Helper 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.

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
October Events

Mark Your Calendars

So many events happening this month - don't miss out!

 WHAT’S NEXT AT MICROSOFT IGNITE 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Register for a Free Workshop.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

Users online (3,419)