The discussion revolves around making an API call to have a user watch specific categories in Discourse. SwisherSweet initially asks about the API call but cannot find it in the documentation. pfaffman suggests reverse-engineering the API, but SwisherSweet is concerned about the API documentation being incomplete.
Osama provides a solution using jQuery Ajax, and kgoetz offers an alternative method via Python requests, which sets the watch list directly against the user. Both methods require an API key and username.
jord8on asks if it’s possible to create a hyperlink with a URL parameter that would allow users to watch a category with a specific notification level when clicked. However, pacharanero points out that this would require a REST POST action, which cannot be achieved with a simple hyperlink, and suggests writing a plugin or theme component as a solution.
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?
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?
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
أعتقد أن كتابة ذلك كملحق أو مكون لقالب سيكون أمرًا مباشرًا نسبيًا، وهو نوع من الكيانات القابلة للتضمين يمكنها تنفيذ هذه الإجراءات نيابةً عنك. المشكلة في كود AJAX المذكور أعلاه هي أنك ترسل مفتاح API العالمي لجميع المستخدمين إلى العميل. هذا بالتأكيد فكرة سيئة.
المشكلة التي ستواجهها عند إنشاء رابط، وفقًا للموضوع الأصلي، هي أن استدعاء الـ API يتطلب إجراء POST عبر REST، بينما يمكن للروابط إصدار إجراء GET عبر REST فقط.