HTML not working i log note field from API

Trying to add some logs with a bit of statistics in the notes field of an oversvation log via the API.

HTML seems to work only if I type it directly in the notes field.
I think I’ve paid notice of this before, but cant remember or find it.

Is it a bug, or do I have to add something more in the json?

1 Like

@pat Can you share an example of the JSON you are trying to POST?

You may need to include "format": "default" alongside the "value" property of the notes field, if you aren’t already, like this:

"notes": {
  "value": "These are my notes.",
  "format": "default"

Drupal allows different “text formats”, and each defines what “filters” are enabled on them. The default format has a filter that allows certain HTML tags.

So if the log you are creating via API doesn’t have "format": "default" then that would explain why your HTML doesn’t work. Take a look at the log’s JSON to check.

Despite the name default, this text format is actually not a Drupal default. It is provided by farmOS, and we set it as the default text format on logs and assets. But perhaps it doesn’t use it automatically if you omit format in the API JSON.

That was it…

Thanks. I’ve seen this before… :face_with_open_eyes_and_hand_over_mouth:

1 Like


It does beg the question: should farmOS try to automatically set the format if it isn’t included in API requests? That would match UI behavior…

I’m not exactly sure how to do that in farmOS code, or if it’s possible, but there’s probably a way. :person_shrugging:

1 Like