Actualizar una publicación mediante una solicitud PUT de la API

Solo para entender, la documentación de la API de Discourse menciona este tipo de… estructura…

{
"post[raw]": "string",
"post[raw_old]": "string",
"post[edit_reason]": "string",
"post[cooked]": "string"
}

Antes de intentarlo, ¿significa esto, o bueno… qué significa esto?

¿Significa esto: {post: {raw: ..., raw_old: ... }}

O simplemente {raw: "", raw_old: ""...}

Y también, ¿qué es raw_old? Solo dice que cada elemento es una “cadena” de lo que debo PUT: en el cuerpo JSON.

Simplemente estoy intentando agregar una línea en la parte superior del post (que fue creado inicialmente por un Bot) donde necesitamos agregar un enlace a otro sitio. Nota también que con el objetivo de que ese primer párrafo se muestre debajo del título de la categoría, o en el elemento cooked

que se mostrará (definido justo debajo del título de la categoría).

Espero que esto tenga sentido. Si no es así, pídamelo aclarar.

I’m not actually sure what raw_old is for at the moment, but you just need to use the raw field and it will replace the entire post. So, in your code you would fetch the post you want to edit, add your line to the top, then update the post using the raw field.

It might be helpful to see how Discourse does it by editing a post live on your site and inspecting the browser calls:

This is also how the discourse_api gem does it:

Just a question on this, are you referring to different documentation then what is defined at Discourse API Docs ? That would be interesting… however I am only going by the API docs.

My simple goal is to simply add a comment + link below the category name, which I think Discourse takes from the first Post of the "About … " topic? Like I’m just looking for what it will insert into the

… element or what I need to do to make my post appear there. Does my explanation make sense?

From the above, and from attempting, you can not update a post using “cooked” as the API documentation states, it is however possible with “raw”, all attempts I made using “cooked” kept giving me back an error that my post was invalid as it was under 20 characters, or not a clear sentence …

However there are additional issues with “raw” that I will make into another post as this isn’t directly related.

Thanks for all your help.

There is a slight discrepancy in API Docs:

Documentation says: PUT /posts/{id}.json with payload

Content type: application/json

{
  "post[raw]": "string",
  "post[raw_old]": "string",
  "post[edit_reason]": "string",
  "post[cooked]": "string"
}

but this only works with PUT /posts/{id} and Content-Type: application/x-www-form-urlencoded.

The correct payload for PUT /posts/{id}.json should be:

Content type: application/json

{
  "post": {
      "raw": "string",
      "raw_old": "string",
      "edit_reason": "string",
      "cooked": "string"
    }
}

The raw parameter is sufficient for replacing the entire post.

Sí, gracias, me di cuenta de esto después de intentar algunas solicitudes en Postman y probarlo… también, en mis intentos, “cooked” parecía no hacer nada… y aún no estoy seguro de qué es “raw_old”.

Esto se ha retrasado hoy y se me ha asignado. Quizás se me pueda quitar la asignación :slight_smile:

En cualquier caso, la documentación ahora es correcta: Discourse API Docs.