API: Create a category but append/add to description more details

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…

  1. create category (working)
  2. 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”

「いいね!」 1

Hi, Andrew.

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.

「いいね!」 2

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.

こんにちは、この古いトピックを掘り起こしています。

description_textdescription の違いを理解する方法はありますか?

:slight_smile: を見つける以外に意味がありますか?

もしかしたら @alank さんがもう見つけたかもしれません!

ありがとうございます!

「いいね!」 1

ドキュメント化されていない場合は、discourse リポジトリの spec ファイルを検索すると、プログラミング言語の基本的な仕組みを理解していれば、このようなことがわかります。

この場合、category spec の次の行は、description_textdescription から派生し、description を設定した直後に利用可能であることを示しています。

これは、description が説明の生の文字列であり、設定されると、調理されて description_text に割り当てられることを意味します。または、description_text はアクセス時に計算される可能性もありますが、その可能性は低いでしょう。いずれにしても、設定すべきは description です。

「いいね!」 1

サイモンさん、ありがとうございます。これで両方のパラメータの違いが明確になりました。

しかし、試してみたところ、これらのパラメータはカテゴリの説明(または「カテゴリについて」の投稿)には実際には設定されていません。したがって、OPの問題は残ったままです。

追記:categories.jsonファイルにこれらの説明パラメータがあることは確認できましたが、API経由で設定する方法がわかりません!

POST リクエストペイロードにドキュメント化されていない場合、たとえそれが機能したとしても、そのように設定できるとは限りません。

行うべきことは、カテゴリ作成後のレスポンスで topic_url を確認し、その URL から取得した ID を使用して 単一トピックを取得 することだと思います。レスポンスの post_stream を確認してください。これは投稿の配列を含んでおり、おそらく 1 つの要素が含まれているはずです。

その投稿の ID を取得し、次に 単一投稿を更新 して説明を追加します。これにより、Discourse で投稿を編集するのと同じようにカテゴリの説明が更新されるはずです。同じ最初の行のルールが適用されます。

「いいね!」 1

投稿しようとしていたところでした、まさにその通りです :slight_smile:

    ## カテゴリを作成
    ret_cat = client.create_category(name, color = color, **kwargs)

    ## 最初の投稿IDを取得 
    cat_id = ret_cat["category"]["id"]
    print("Cat id", cat_id)
    topics = client.category_topics(cat_id)
    first_post_id = client.topic_posts(topics["topic_list"]['topics'][0]["id"])['post_stream']['posts'][0]['id']
    ## 最初の投稿を変更
    ret_post = client.update_post(first_post_id, cat["about_msg"],"set up")
「いいね!」 3