No description in a category via API

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 migration

1 Like

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 !

1 Like