# API & ViewCount

**URL:** <https://forums.plex.tv/t/api-viewcount/506375>\
**Category:** Apps & Creations\
**Tags:** other-third-party, other-dev\
**Created:** [December 11, 2019, 6:42am UTC](https://forums.plex.tv/t/api-viewcount/506375 "2019-12-11T06:42:55Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![dTos](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/dtos/32/138254_2.png) [@dTos](https://forums.plex.tv/u/dTos)\
**Post date:** [December 11, 2019, 6:42am UTC](https://forums.plex.tv/t/api-viewcount/506375/1 "2019-12-11T06:42:56Z")

</div>

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](https://plex.tv/users/sign_in.json)
2. Retrieving user list for uuids – [https://plex.tv/api/v2/home/users](https://plex.tv/api/v2/home/users)
3. Switching account to home user – [https://plex.tv/api/v2/home/users/[user.uuid]/switch](https://plex.tv/api/v2/home/users/%5Buser.uuid%5D/switch) to retrieve home user authToken
4. Query a server endpoint using home user authToken – [https://myserver:32400/library/sections/5/all?type=4](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?

---

<div class="post-metadata">

**Author:** ![anon18523487](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@anon18523487](https://forums.plex.tv/u/anon18523487)\
**Post date:** [December 12, 2019, 12:25am UTC](https://forums.plex.tv/t/api-viewcount/506375/2 "2019-12-12T00:25:36Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dane22](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/dane22/32/4389_2.png) [@dane22](https://forums.plex.tv/u/dane22)\
**Post date:** [December 12, 2019, 1:23am UTC](https://forums.plex.tv/t/api-viewcount/506375/3 "2019-12-12T01:23:17Z")

</div>

> [@anon18523487](#):
>
> I don’t know if a way to get the total play count from all users

> **[Movie Export Level](https://github.com/ukdtom/ExportTools.bundle/wiki/Movie-Export-Level#playcount-1-req-pms-v115-or-above)**
>
> Export tools for Plex. Contribute to ukdtom/ExportTools.bundle development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![dTos](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/dtos/32/138254_2.png) [@dTos](https://forums.plex.tv/u/dTos)\
**Post date:** [December 12, 2019, 6:22pm UTC](https://forums.plex.tv/t/api-viewcount/506375/4 "2019-12-12T18:22:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dane22](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/dane22/32/4389_2.png) [@dane22](https://forums.plex.tv/u/dane22)\
**Post date:** [December 12, 2019, 9:05pm UTC](https://forums.plex.tv/t/api-viewcount/506375/5 "2019-12-12T21:05:10Z")

</div>

> [@dTos](#):
>
> What am I missing here?

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…

---

<div class="post-metadata">

**Author:** ![anon18523487](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@anon18523487](https://forums.plex.tv/u/anon18523487)\
**Post date:** [December 12, 2019, 9:16pm UTC](https://forums.plex.tv/t/api-viewcount/506375/6 "2019-12-12T21:16:12Z")

</div>

> [@dTos](#):
>
> Not looking for playcount for all users, just one user at a time.

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.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/plex/original/3X/2/a/2acb9765406f63293d357b4ec509ec39aa28f2ad.png) [@system](https://forums.plex.tv/u/system)\
**Post date:** [March 11, 2020, 9:16pm UTC](https://forums.plex.tv/t/api-viewcount/506375/7 "2020-03-11T21:16:20Z")

</div>

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