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 curtida

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 curtidas

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.

Olá, desenterrando este tópico antigo..
Existe alguma maneira de entender qual a diferença entre description_text e description?
Quero dizer, exceto descobrindo isso :slight_smile:
talvez @alank já tenha descoberto!
Obrigado!

1 curtida

Se não estiver documentado em outro lugar, pesquisar nos arquivos de especificação no repositório discourse responderá a perguntas como esta com um entendimento básico de como as linguagens de programação funcionam.

Neste caso, as seguintes linhas na especificação da categoria mostram que description_text é derivado de description e imediatamente disponível após a configuração de description.

Isso me diz que description é a string bruta para a descrição e, ao configurá-la, ela é processada e atribuída a description_text. Ou description_text pode ser calculado quando acessado, mas duvido, de qualquer forma description é o que deve ser configurado.

1 curtida

Obrigado Simon, isso esclarece a diferença entre ambos os parâmetros.

No entanto, acabei de tentar e nenhum desses dois parâmetros está realmente definido na descrição da categoria (ou na postagem da categoria Sobre). Portanto, o problema do OP permanece.

Adicionando: Vejo no arquivo categories.json que esses parâmetros de descrição são o que eu quero, mas de alguma forma não consigo defini-los através da API!

Se eles não estiverem documentados para a carga útil da solicitação POST, você não poderá contar com a capacidade de defini-los dessa forma, mesmo que funcione.

Suspeito que a coisa a fazer é olhar para o topic_url na resposta após criar a categoria, então obter um único tópico usando o ID desse URL. Olhe para o post_stream na resposta, que tem uma matriz de posts, imagino que terá um elemento.

Obtenha o ID desse post e então atualize um único post para adicionar sua descrição. Isso deve acionar a descrição da categoria sendo atualizada da mesma forma que editar o post no Discourse, a mesma regra da primeira linha.

1 curtida

Eu estava prestes a postar, foi exatamente o que eu fiz :slight_smile:

    ## criar categoria
    ret_cat = client.create_category(name, color = color, **kwargs)

    ## obter o id do primeiro post 
    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']
    ## modificar o primeiro post
    ret_post = client.update_post(first_post_id, cat["about_msg"],"set up")
3 curtidas