I’m using API request to Discourse to create a category, however in the same process I would like to add text or URL reference etc, to Category description (or is it description_text as I try to understand the properties or differences).
Note also that there might be a “robot” adding to this, so the best way…
create category (working)
Update category or more so append the link, but to category.description or category.description_text)?
However there are no properties on update except name, color, text_color, so are there other properties I can send? Like (and which) description or/maybe description_text?
All I want to do is add a slug link to a site related to the category I’m creating… or simply add at the end of the Discourse Category description “[link][https/example.projectxxx”
Although the docs only list those 3 properties, most of the properties mentioned in the Response object can be set on the create call. I found this out when I needed to script the creation of a large number of categories with the same settings except for the name and slugs.
The only property I needed to set and consistently had issues with is the permissions.
Yes, I’ve noticed that properties allowed are not those defined in the API documentation.
However to set the Category “description” which is very confusing as the category description is not at all what is displayed, in fact below the category name is the HTML element “cooked” which is empty, so how to set that…
From what I’ve been able to understand, I must set a post in the “About the --category name-- …” and it must be the first post in that category, but I think there is other critaria, like the cooked or also the fact that we have a Bot that first posts there.
I’ve tried adjusting the created_at/updated_at dates to make my post appear above so that the category will grab or use that description, but no luck! There must be something I’m not understanding about the “cooked” and/or category description. Very confusing and I’ve found no docs, but I’ll keep looking, if anyone has ideas on what to try, please let me know.
Hi, digging up this old topic…
Is there any way to understand what the difference between description_text and description is?
I mean except finding it out by doing
maybe @alank found it out by now!
Thanks!
If it’s not documented elsewhere, searching within the spec files in the discourse repository will answer things like this with a basic understanding of how programming languages work.
In this case, the following lines in the category spec show that description_text is derived from description and immediately available after setting description.
This says to me that description is the raw string for the description and upon setting it, it gets cooked and assigned to description_text. Or description_text could be calculated when accessed but I doubt it, either way description is the one to set.
thanks Simon, that clarifies the difference between both parameters.
However, I just tried and none of those two parameters are actually set in the category description (or the About category post). So the issue of the OP remains.
Adding: I see in the categories.json file that these description parameters are what I want, but I somehow cannot set them through the API!
If they aren’t documented for the POST request payload, you can’t rely on being able to set them like that even if it happened to work.
I suspect the thing to do is to look at the topic_url in the response after creating category, then get a single topic using the id from that URL. Look at the post_stream in the response which has an array of posts, I imagine that will have one element.
Get the id of that post and then update a single post to add your description. That should trigger the category description being updated the same as editing the post in Discourse, same first line rule.