您好,
我仍在将数据从旧应用程序导入到我们的新 Discourse。
我无法通过以下 API 调用创建带有描述的类别:
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"
类别已创建,但没有描述。
我收到以下响应:
{"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", [...]}
感谢您的帮助。
Canapin
(Coin-coin le Canapin)
2
你好 
分类的描述是自动创建的“关于”主题的内容。默认文本可能被视为“null”,直到它被编辑。
我认为在创建分类的请求中没有可用的“description”参数,你需要发出另一个 API 请求来更新“关于”主题的第一个帖子。
根据你的导入过程,你可能想使用一个合适的导入脚本而不是使用 API。请参阅 Migration
1 个赞
感谢您的回复
我创建了这个脚本,允许您创建一个类别,然后修改其描述:
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"
}
}'