elements icon indicating copy to clipboard operation
elements copied to clipboard

Rest API RICH_TEXT type fields reported as type STRING.

Open du8die opened this issue 1 year ago • 0 comments

In the API Browser (https://twenty.com/developers/rest-api), endpoints with a RICH_TEXT typed property are reported as STRING. Submitting the test code causes an error message to be inserted into the body field, causing the module to break.

Context

We rely on the API browser to understand how to use the API. The API documentation should be accurate.

Current Behavior

On submitting the following payload to the /rest/notes endpoint (POST), an error is returned.

{
  "position": 0,
  "title": "string",
  "body": "string",
  "createdBy": {
    "source": "EMAIL"
  }
}

The following error is returned:

{
  "statusCode": 400,
  "messages": [
    "Unexpected token s in JSON at position 0"
  ],
  "error": "Bad Request"
}

On investigation, I realized that a record was created - and that the error message was being inserted into the body field of the notes record in the database. I determined this by repeating the call with different values for the title and body fields. When both values were different, the error returned the first letter of the body string I provided. For example, I used "body":"Test", and "title": "String". The error returned was Unexpected token T in JSON at position 0.

Because the error indicates that the body field has invalid JSON, the /rest/notes GET call fails with the following error:

{
  "statusCode": 400,
  "messages": [
    "Unexpected token s in JSON at position 0"
  ],
  "error": "Bad Request"
}

When this happens, there is no way (on the paid hosted version at least) to correct this issue. The Notes feature is completely broken.

Expected Behavior

The API Explorer should be updated to indicate that the body field is RICH_TEXT, and provide instructions on how to format the field. It should also warn users that incorrectly formatted JSON may break the tool. Technically, the documentation is not "wrong", but submitting the suggested payload will cause the module to break.

Possible Workaround/Solution

  1. Include code that validates that the body field submitted actually contains JSON, and that it is valid for the field type. Do not save the record if the field fails the validation.
  2. Update the API Explorer to accurately reflect the data types and JSON structure for the body field.

Steps to Reproduce

Please see above.

Environment

  • Version used: Paid Hosted
  • Environment name and version (e.g. Chrome 39, node.js 5.4): Chrome 131
  • Operating System and version (desktop or mobile): Windows 11 Pro
  • Link to your environment/workspace/project: N/A

du8die avatar Dec 12 '24 01:12 du8die