Hello, We have installed the “Solved” plugin and we are creating Categories programmatically using python script, we want to set this Category setting fields as “True” . While running the script, it says that updated successfully but when we check this category settings field - it is not set to “True” and it is still in “False”. how to debug & fix this issue.
I always follow Reverse engineer the Discourse API for such questions.
From what I know, if you are building categories with a script, I assume you are using JSON to add the categories. You would have to make some changes to the endpoint and the script. You can also refer to this documentation: Discourse Categories API.
However, Discourse is a powerful tool. You can check out this guide: Reverse Engineering the Discourse API. Since Discourse is backed by a complete JSON API, you can reverse engineer it, make the necessary alterations, and get it to work as needed.
A quick hint:
- Change the desired “Solved” setting manually in the UI.
- Inspect the network requests made by the browser to identify the exact API endpoint, request method (e.g.,
PUT
), and payload.
In python script it would look something like this:
payload = {
"enable_solved": True # Adjust this
}
response = requests.put(url, headers=headers, json=payload)
if response.status_code == 200:
print("Category updated")
else:
print(f"Failed: {response.status_code} - {response.text}")
update_category_settings(category_id=123)
PS: I’m not entirely sure about this, but I recently built some scripts, so this response is based on the things I have come across so far.
Thank You Mihir, it did help to resolve this issue. Appreciate your input and suggestions.
Thank you Thomas for pointing out to this approach.
I’m glad it helped