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

According to a reply by @Falco on my post, 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 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.

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.

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?

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

Have you figured out how to achieve this?

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

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);
});

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.

لست متأكدًا مما إذا كان هذا الكود يمكنه تحقيق ما أبحث عنه، ولكن…

أود إضافة رابط تشعبي يحتوي على معامل URL معين، بحيث عندما ينقر المستخدم على الرابط، يتم تعيين حالة مراقبته/تتبعه/حاله الطبيعي/صمته لفئة معينة.

حالة الاستخدام العملية ستكون بدلاً من أن أقول للناس “قم بزيارة الفئة… وانقر على أيقونة الجرس واختر _____”، يمكنني أن أقول شيئًا مثل…

انقر هنا إذا كنت ترغب في تلقي إشعار عند إضافة منشور جديد إلى هذا المنتدى.

عندئذٍ، عندما ينقر المستخدم على ذلك الرابط التشعبي، سيتم اشتراكه بالمستوى الذي نحدده في معامل الرابط.

أعتقد أن كتابة ذلك كملحق أو مكون لقالب سيكون أمرًا مباشرًا نسبيًا، وهو نوع من الكيانات القابلة للتضمين يمكنها تنفيذ هذه الإجراءات نيابةً عنك. المشكلة في كود AJAX المذكور أعلاه هي أنك ترسل مفتاح API العالمي لجميع المستخدمين إلى العميل. هذا بالتأكيد فكرة سيئة.

المشكلة التي ستواجهها عند إنشاء رابط، وفقًا للموضوع الأصلي، هي أن استدعاء الـ API يتطلب إجراء POST عبر REST، بينما يمكن للروابط إصدار إجراء GET عبر REST فقط.