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 „Gefällt mir“

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 „Gefällt mir“

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.

Hallo, grabe dieses alte Thema aus…

Gibt es eine Möglichkeit zu verstehen, was der Unterschied zwischen description_text und description ist?
Ich meine, außer es durch Ausprobieren herauszufinden :slight_smile:
vielleicht hat @alank es inzwischen herausgefunden!
Danke!

1 „Gefällt mir“

Wenn es nicht anderswo dokumentiert ist, beantwortet die Suche in den Spec-Dateien des Discourse-Repositorys solche Fragen mit einem grundlegenden Verständnis der Funktionsweise von Programmiersprachen.

In diesem Fall zeigen die folgenden Zeilen in der Kategorie-Spezifikation, dass description_text von description abgeleitet und sofort nach dem Setzen von description verfügbar ist.

Das bedeutet für mich, dass description der Rohstring für die Beschreibung ist und beim Setzen dieser wird er verarbeitet und description_text zugewiesen. Oder description_text könnte berechnet werden, wenn darauf zugegriffen wird, aber das bezweifle ich, auf jeden Fall ist description das, was gesetzt werden muss.

1 „Gefällt mir“

Danke Simon, das klärt den Unterschied zwischen beiden Parametern.

Ich habe es jedoch gerade versucht und keiner dieser beiden Parameter ist tatsächlich in der Kategoriebeschreibung (oder dem Beitrag über die Kategorie) festgelegt. Das Problem des OP bleibt also bestehen.

Hinzugefügt: Ich sehe in der Datei categories.json, dass diese Beschreibungsparameter das sind, was ich will, aber ich kann sie irgendwie nicht über die API einstellen!

Wenn sie nicht für die POST-Anfrage-Payload dokumentiert sind, können Sie sich nicht darauf verlassen, dass Sie sie auf diese Weise festlegen können, auch wenn es zufällig funktioniert.

Ich vermute, dass Sie die topic_url in der Antwort nach dem Erstellen der Kategorie nachschlagen und dann ein einzelnes Thema abrufen müssen, indem Sie die ID aus dieser URL verwenden. Betrachten Sie den post_stream in der Antwort, der ein Array von Beiträgen enthält. Ich stelle mir vor, dass dieser ein Element haben wird.

Rufen Sie die ID dieses Beitrags ab und aktualisieren Sie dann einen einzelnen Beitrag, um Ihre Beschreibung hinzuzufügen. Dies sollte die Aktualisierung der Kategoriebeschreibung auslösen, genau wie beim Bearbeiten des Beitrags in Discourse, dieselbe Regel für die erste Zeile.

1 „Gefällt mir“

Ich wollte gerade posten, das ist genau das, was ich getan habe :slight_smile:

    ## Kategorie erstellen
    ret_cat = client.create_category(name, color = color, **kwargs)

    ## Erste Beitrags-ID abrufen 
    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']
    ## Ersten Beitrag ändern
    ret_post = client.update_post(first_post_id, cat["about_msg"],"set up")
3 „Gefällt mir“