cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
golfnutt82
Post Patron
Post Patron

Remove User from SharePoint document library folder User Group

Good morning,
I am at my wits end trying to figure this out.
I have tried just about every solution I found on this site and others and I still can figure out how to remove a user from a SharePoint user group. What am I missing?
Thank you!


Here is what I have now:

golfnutt82_0-1636377630177.png

Here's what is being returned:

golfnutt82_3-1636377852910.png

golfnutt82_2-1636377760727.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
eliotcole
Power Participant
Power Participant

Yeah, that LoginName is not the same as Name, @golfnutt82, that's for certain.

 

If you could also do some StartPage fu (never Google 😉) to see if you can find the LoginName format that'd be awesome.

 

EDIT - OK, I just did an _api/site/Owner call which showed me my LoginName, and it's in this format, so you need to extract whatever looks like this from your previous step:

 

 

c:0o.c|federateddirectoryclaimprovider|aaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee_o

 

 

EDIT 2 - So probably grabbing d.LoginName would work for you if you're already getting userData somewhere else, like an _api/Web/GetUserById(6) request (with the appropriate Id, of course) ...

 

Which reminds me ... I can't remember if I mentioned it already, but perhaps if you already have that Id, you could try the following (obviously not with a 6 in there):

 

_api/web/sitegroups/GetById(3747)/Users/RemoveById(6)

 

Having a brief look around that appears to work for others, and you don't have to worry about format.

 

EDIT 3 - Oh, also, @golfnutt82, if you wanna make the data you get a bit more honed in, then you can use the ODATA filters like a boss to perform filter and select actions to really needle the data you get from calls:

https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/use-odata-query-operations-in-sharepoint-...

View solution in original post

16 REPLIES 16
eliotcole
Power Participant
Power Participant

Hiya, @golfnutt82 , good to see you again. 👋

 

Could you show (however obfuscated) the whole flow, so there's some more context, please?

 

Also, could you please send the whole error message from that status 400 message?

 

Oh, and one question: Is the SharePoint group that you're referring to a native SP group, or a 365 group?

 

---

 

Separately, my initial instinct from what I can see (ODATA error) is that you're missing some additional information on the end of your SharePoint HTTP request, or perhaps just slightly mis-configured in the JSON. However ODATA stuff is usually handled in the URI.

 

EDIT - This document (not directly relateable, perhaps) seems to support that.

 

Try adding a bracketed (loginName) after the last word in the URI like so ... obviously placing the actual login name there 😉:

_api/web/sitegroups/GetById(3747)/Users/RemoveByLoginName(loginName)

 

golfnutt82
Post Patron
Post Patron

Hello again,
Here is more of the workflow.
Yes these are standard SP groups

golfnutt82_3-1636378954435.png

golfnutt82_4-1636379025413.png

 

 


The 400 message continued is.

golfnutt82_0-1636378502682.png

golfnutt82_1-1636378535095.png

golfnutt82_2-1636378576128.png

 

 

eliotcole
Power Participant
Power Participant

Nice one, thanks.

 

Would definitely be cool to see more of that "message" header, though. The one that begins: "{\"odata.error\":{\"code\":\"-1..."

 

If that pure flailing attempt at a fix (putting the ODATA information in the URI) seems to be something that could work out, @golfnutt82 ... then I'm also thinking that if you're extracting the user's ID, then you may just wish to use removeById(), instead. Same thing, put it in the URI there.

golfnutt82
Post Patron
Post Patron

I actually tried this and the workflow ran but didnt remove the user from the group.

golfnutt82_0-1636382327468.png

 



eliotcole
Power Participant
Power Participant

OK, but (on the incident that you have reported) have you tried adding a bracket to the end of the RemoveByLoginName string with the Login Name?

 

_api/web/sitegroups/GetById(3747)/Users/RemoveByLoginName(loginName)

 

Hi, yep did that and still have an error.

golfnutt82_0-1636385143269.png

 

eliotcole
Power Participant
Power Participant

OK, @golfnutt82, can you please show me your HTTP request for this specific action, from the edit screen, as it looks right now?

golfnutt82_0-1636385675762.png

 

I gave you the wrong error output. 
Here is the correct one.

golfnutt82_1-1636385902146.png

 

eliotcole
Power Participant
Power Participant

OK, that's odd, have you tried googling any of these errors?

 

If I was just reading this blank, this error would suggest that the last time it was run it still had the Body that you specified in your opening post.


@golfnutt82 wrote:

"The parameter 'LoginName' in the request payload is not a valid parameter for the function import 'RemoveByLoginName'."


Otherwise it is data that is coming out of nowhere, to be honest ... and I'm baffled by it.

eliotcole
Power Participant
Power Participant

OK, that's a bit more progressive, @golfnutt82 🙂 ... what we know now is that you're submitting properly, but just need to format it properly.

 

I suspect the login name doesn't have text with a comma after it. Most likely it's an email address, or the part that comes before the email address.

 

I believe I used it the other week, lemme just check.

 

In the meantime, take a look around for the LoginName format. 👍

Here is the user group associated with the library.

 

golfnutt82_2-1636386522476.png

 

golfnutt82_1-1636386460323.png


Here is the library:

golfnutt82_3-1636386625793.png

Yes, I am baffled as well.
Ive tried everything

 

eliotcole
Power Participant
Power Participant

Yeah, that LoginName is not the same as Name, @golfnutt82, that's for certain.

 

If you could also do some StartPage fu (never Google 😉) to see if you can find the LoginName format that'd be awesome.

 

EDIT - OK, I just did an _api/site/Owner call which showed me my LoginName, and it's in this format, so you need to extract whatever looks like this from your previous step:

 

 

c:0o.c|federateddirectoryclaimprovider|aaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee_o

 

 

EDIT 2 - So probably grabbing d.LoginName would work for you if you're already getting userData somewhere else, like an _api/Web/GetUserById(6) request (with the appropriate Id, of course) ...

 

Which reminds me ... I can't remember if I mentioned it already, but perhaps if you already have that Id, you could try the following (obviously not with a 6 in there):

 

_api/web/sitegroups/GetById(3747)/Users/RemoveById(6)

 

Having a brief look around that appears to work for others, and you don't have to worry about format.

 

EDIT 3 - Oh, also, @golfnutt82, if you wanna make the data you get a bit more honed in, then you can use the ODATA filters like a boss to perform filter and select actions to really needle the data you get from calls:

https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/use-odata-query-operations-in-sharepoint-...

Hello Eliot,
Sorry I fell off the map for awhile due to having to work on other things.
I did use the following without success:

golfnutt82_0-1636475923343.png

golfnutt82_3-1636476245551.png

 

I will try your edit two suggestion now.

 

YES! Your EDIT 2 suggestion worked!!!
Thank  you!

golfnutt82_1-1636476809768.png

 

 

eliotcole
Power Participant
Power Participant

Niiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiice, @golfnutt82 🏆🏆🏆🏆

 

Oh! ... and it turns out that I had mentioned it a bit earlier ... but what matters is that you're now able to remove those users. 👍

Helpful resources

Announcements
2022 Release Wave 1 760x460.png

2022 Release Wave 1 Plan

Power Platform release plan for the 2022 release wave 1 describes all new features releasing from April 2022 through September 2022.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Top Solution Authors
Top Kudoed Authors
Users online (1,478)