jensenkd / plex-api

.NET Core SDK for Plex Media Server
MIT License
86 stars 27 forks source link

GetUsers not Returning all Users #71

Closed elzik closed 2 years ago

elzik commented 2 years ago

Describe the bug PlexAccountClient.GetUsers() does not return all users; it returns all users other than the Home Admin user.

To Reproduce Steps to reproduce the behavior:

  1. Visit the Home & Library Access page in Server Settings in Plex to see the list of users.
  2. Make a call to PlexAccountClient.GetUsers().
  3. See that the returned users does not include the Home Admin.

Expected behavior A call to PlexAccountClient.GetUsers() should include all users including the Home Admin.

Additional context Looking at the implementation of PlexAccountClient.GetUsers() I see that it uses a base URI of https://plex.tv/api/users. I have confirmed that is this base URI is changed to https://plex.tv/api/home/users then all users, including the Home Admin users, are returned as expected.

Is there some reason why we shouldn't hit the /home/users endpoint? Is there any desire to either fix the existing method so that it does hit this endpoint or create an additional one?

jensenkd commented 2 years ago

I don’t see any reasons. Let me take a quick look at the new api endpoint.

elzik commented 2 years ago

I did ask about this on the PLex forums and got a response from a Plex employee:

https://plex.tv/api/home/users will return users, that is in your [home](https://support.plex.tv/articles/203815766-what-is-plex-home/) only https://plex.tv/api/users will return all your friends, incl. those in your home

So it sounds like there is a distinction between these two endpoints. One is related to all your "friends" and the other one to just users in your home. Do you think that this would map better to two different methods in plex-api, making it clearer what will be returned?

elzik commented 2 years ago

@jensenkd would you be open to a pull request that leaves the existing method as-is and adds a new method: GetHomeUsers()?

jensenkd commented 2 years ago

@elzik I already built the new method GetHomeUsers() and will be releasing soon. Thanks for confirming my approach with the plex team. I'll have a nuget build shortly.

elzik commented 2 years ago

That's great news and much appreciated, thanks.

elzik commented 2 years ago

@jensenkd I noticed that in the friend vs home user responses, the shape of the user was significantly different. The only things they have in common are id, protected, title & thumb. Are you planning to have two separate models, one for User and one for HomeUser?

The reason I mention this is that my use case requires the admin attribute of the User element that is only returned in the home users response.

elzik commented 2 years ago

@jensenkd I see the recent commit for this, thank you. Is the intention to lose the original GetUsers() method? The two endpoints return different things even though there is an overlap and the information returned for each user is also different. It would be useful to have a GetHomeUsers() and the original GetUsers().

To keep my project going whilst I was waiting for the new package, I forked and created a branch with both methods in, each with their own models for a User and a HomeUser as they represented different things.

jensenkd commented 2 years ago

@elzik It looks like the terminology that Plex uses is HomeUsers() and Friends() as the two different types of users. I think it probably makes sense to mimic that in GetHomeUsers() and GetFriends(). Thoughts?

HomeUser and Friend would be different classes

elzik commented 2 years ago

@jensenkd Yes, I think you're right - it's good to use the same terminology that Plex themselves use.

The PlexAccountClient already has a GetFriendsAsync() method but that doesn't seem to return anything on my server. Whereas the original GetUsers() method returned the users who have been invited and have access to my server but who have not necessarily accepted the invitation to be a home user.

Are you suggesting changing the GetFriendsAsync() method so that it hits the https://plex.tv/api/users endpoint?

jensenkd commented 2 years ago

No, I'm suggesting using https://plex.tv/api/v2/friends.json

That does not return anything for you?

elzik commented 2 years ago

My mistake, I think it was the other home users endpoint that was returning nothing but I have now taken your latest changes and everything seems to work well. I can get exactly what I need now by calling GetHomeUsersAsync() and GetFriendsAsync().

Thank you for the updates; I'll close this and look forward to the NuGet package.