No description in a category via API

AI-generated summary

The issue is with creating a category via API and including a description. According to Canapin, the description of a category is the content of the automatically created “About” topic, and there’s no available “description” parameter in the request to create a category.

FLucas created a script to work around this by first creating the category and then modifying the first post of the “About” topic to add the description. The script can be found in FLucas’s post.

The solution worked, as confirmed by FLucas in response to Canapin’s inquiry.

Hi,

I’m still importing data from an old app into our new Discourse.
I can’t create a category with its description with the following API call :

curl -X POST "https://site-discourse/categories.json" \
-H "Api-Key: api-key" \
-H "Api-Username: api-username" \
-d "name=categorie test" \
-d "description=Description De La Categorie"

The category is created but there is no description.

I get the following response:

{"category":{"id":21,"name":"categorie test",[...],"slug":"categorie-test", [...] **,"description":null**,"description_text":null,"description_excerpt":null,"topic_url":"/t/a-propos-de-la-categorie-categorie-test/12286", [...]

Thanks for your help

Hi :blob_wave:

The description of a category is the content of the automatically created “About” topic. The default text is probably considered “null” until it’s edited.

I think there’s no available “description” parameter in the request to create a category, and you need to make another API request to update the first post of the About topic.

Depending on your importing process, you might want to use a proper import script instead of using the API. See Support > Migration

Thank you for your reply

I created this script allowing you to create a category and then modify its description:

curl -X POST "https://site-discourse/categories.json" \
 -H "Api-Key: api-key" \
 -H "Api-Username: api-username" \
 -d "name=Catégorie 1"
 
sleep 2 
 
latest_posts_response=$(curl -X GET "https://site-discourse/posts.json" \
 -H "Content-Type: application/json" \
 -H "Api-Key: api-key" \
 -H "Api-Username: api-username") 
                 
post_id=$(echo $latest_posts_response | jq  '.latest_posts[0] .id')
   
curl -X PUT "https://site-discourse/posts/$post_id.json" \
 -H "Content-Type: application/json" \
 -H "Api-Key: api-key" \
 -H "Api-Username: api-username" \
 -d '{
        "post": {
        "raw": "Description de la catégorie 1"
      }
     }'

Did it work in the end?

Yes thank you it works !