# API call to have a user watch specific category(ies)?

**URL:** https://meta.discourse.org/t/api-call-to-have-a-user-watch-specific-category-ies/67450
**Category:** Development
**Created:** [August 4, 2017, 1:02pm UTC](https://meta.discourse.org/t/api-call-to-have-a-user-watch-specific-category-ies/67450 "2017-08-04T13:02:51Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![SwisherSweet](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/swishersweet/32/119523_2.png) [@SwisherSweet](https://meta.discourse.org/u/SwisherSweet)
#### Post date: [August 4, 2017, 1:02pm UTC](https://meta.discourse.org/t/api-call-to-have-a-user-watch-specific-category-ies/67450/1 "2017-08-04T13:02:51Z")

</div>

According to [a reply](https://meta.discourse.org/t/create-sso-users-adding-to-group-subscribing-to-category-via-api/67335/2) by @Falco on [my post](https://meta.discourse.org/t/create-sso-users-adding-to-group-subscribing-to-category-via-api/67335), there’s a way to set users to watch categories using the API. I’ve spent hours searching the web and combing through the [API documentation](http://docs.discourse.org/) but I cannot find this call.

Does anyone know what API call could be used to set a user to watch a specific category?

Thank you.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [August 4, 2017, 1:15pm UTC](https://meta.discourse.org/t/api-call-to-have-a-user-watch-specific-category-ies/67450/2 "2017-08-04T13:15:05Z")

</div>

You can search for "reverse engineer api " for tips on how to figure out the API call. Also, there is a plugin that will make people in a certain group follow a set of categories.

---

<div class="post-metadata">

### Author: ![SwisherSweet](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/swishersweet/32/119523_2.png) [@SwisherSweet](https://meta.discourse.org/u/SwisherSweet)
#### Post date: [August 4, 2017, 1:33pm UTC](https://meta.discourse.org/t/api-call-to-have-a-user-watch-specific-category-ies/67450/3 "2017-08-04T13:33:48Z")

</div>

Thanks for the reply @pfaffman. Are you suggesting the API documentation is incomplete and I need to reverse engineer the API code to find the undocumented API call?

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [August 4, 2017, 5:19pm UTC](https://meta.discourse.org/t/api-call-to-have-a-user-watch-specific-category-ies/67450/4 "2017-08-04T17:19:27Z")

</div>

if you don’t see what you’re looking for, it’s almost as easy to reverse engineer as use the documentation.

---

<div class="post-metadata">

### Author: ![Osama](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/osama/32/98013_2.png) [@Osama](https://meta.discourse.org/u/Osama)
#### Post date: [August 11, 2017, 2:03pm UTC](https://meta.discourse.org/t/api-call-to-have-a-user-watch-specific-category-ies/67450/5 "2017-08-11T14:03:16Z")

</div>

Have you figured out how to achieve this?

Here is how to do it using jQuery Ajax for anyone interested:

```javascript
const data = {
	notification_level: 3, 
	api_key: "all_users_api_key",
	api_username: "target_user_username"
};

const settings = {
  url: "/category/{{category_id}}/notifications",
  method: "POST",
  data: data
};

$.ajax(settings).done(response => {
  console.log(response);
});

```

---

<div class="post-metadata">

### Author: ![kgoetz](https://avatars.discourse-cdn.com/v4/letter/k/bb73d2/32.png) [@kgoetz](https://meta.discourse.org/u/kgoetz)
#### Post date: [October 17, 2017, 4:35am UTC](https://meta.discourse.org/t/api-call-to-have-a-user-watch-specific-category-ies/67450/6 "2017-10-17T04:35:45Z")

</div>

I’m sure @Osama’s method works, but setting user watches via the category seemed a bit weird to me. The following sets the watch list directly against the user (This is via python requests, but shows what is required).

DISCOURSE\_URL - domain, including http(s)  
username - user to change  
DISCOURSE\_API\_KEY - api key generated by, and associated with a user  
DISCOURSE\_API\_USERNAME - user who the key is associated with  
watch\_category - a list of categories the user should be watching

> requests.request(‘PUT’, ‘{0}/u/{1}.json’.format(DISCOURSE\_URL, username), allow\_redirects=False, params={“api\_key”:DISCOURSE\_API\_KEY, “api\_username”: DISCOURSE\_API\_USERNAME}, json={‘watched\_category\_ids’: [watch\_category]}, headers={‘Accept’: ‘application/json; charset=utf-8’})

@SwisherSweet if you end up opening a bug against the docs for missing info on how to modify the watch list/user prefs do post back here with it.

---

<div class="post-metadata">

### Author: ![jord8on](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jord8on/32/166809_2.png) [@jord8on](https://meta.discourse.org/u/jord8on)
#### Post date: [May 21, 2020, 3:48am UTC](https://meta.discourse.org/t/api-call-to-have-a-user-watch-specific-category-ies/67450/7 "2020-05-21T03:48:04Z")

</div>

I’m not sure if this code can accomplish what I’m looking to do, but…

I’d like to add a hyperlink that would have some kind of URL parameter that when a user clicked the link, they would be Watching/Tracking/Normal/Muted for a particular category.

Practical use case would be instead of me telling folks to Visit the category… and click the bell icon and choose \_\_\_\_\_… I could say something like…

**CLICK HERE** if you want to be notified whenever a new post is added to this forum.

Then, when the users clicks that hyperlink, they are subscribed at the level we define, in the url parameter.

---

<div class="post-metadata">

### Author: ![pacharanero](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pacharanero/32/500583_2.png) [@pacharanero](https://meta.discourse.org/u/pacharanero)
#### Post date: [May 21, 2020, 9:59am UTC](https://meta.discourse.org/t/api-call-to-have-a-user-watch-specific-category-ies/67450/8 "2020-05-21T09:59:07Z")

</div>

I think this would be relatively straightforward to write as a plugin or theme component, some kind of embeddable entity which can make these actions for you. The issue with the AJAX code posted above is that you are sending the global all users API key to the client. This is totally a bad idea.

> [@jord8on](#):
>
> **CLICK HERE** if you want to be notified whenever a new post is added to this forum.

The issue you will have with creating a link, as per the OP, is that the API call requires a REST `POST` action and links can only issue a REST `GET` action.
