API & ViewCount

Hi Plex Friends!

I’m working on a project that is powerhsell based, and attempting to reverse engineer the plex APIs, but I can’t seem to get viewcount to show with a unique X-Plex-Client-Identifier or with a new authtoken from signin.json. If I used my client id and auth token from plex web it outputs the view/play status fields just fine. Any thoughts?

I’m doing as follows:

  1. Sign in using username & pw to retrieve authToken for server/home owner account – https://plex.tv/users/sign_in.json
  2. Retrieving user list for uuids – https://plex.tv/api/v2/home/users
  3. Switching account to home user – https://plex.tv/api/v2/home/users/[user.uuid]/switch to retrieve home user authToken
  4. Query a server endpoint using home user authToken – https://myserver:32400/library/sections/5/all?type=4
    Object returned includes an array of “video” objects that do not include “viewCount”.
    (If I use the user’s token from plex web on the same query, the video array provides “viewCount” for each item.)

What am I missing here?

The viewcount is stored per user. I don’t know if a way to get the total play count from all users if that is what you are trying to find.

Thanks. Not looking for playcount for all users, just one user at a time. The issue is that the fields don’t appear in the returned object for the user whose token I’ve sent, and I’m not clear why.

Prefer to go the API approach if I can avoid an export. It would be easy enough for me to grab this from the database directly as well, but would prefer to do it completely remote without a file or db.

Try something like:
/library/sections/2/all?X-Plex-Container-Start=0&X-Plex-Container-Size=50&type=4&customFilter=1&sort=viewCount%3Adesc&filters=show.viewCount%253E%253E%3D0&X-Plex-Token=XXXX

Above will query section 2 (TV-SHOWS) to get only episodes (type=4), and filter them so only those with a viewcount above 0 will be returned.

Also it has paging, so it starts with hit 0, and the next 50 items…

I thought you said you could get them using

(If I use the user’s token from plex web on the same query, the video array provides “viewCount” for each item.).

Just repeat that with the token for each user.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.