Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rest API RICH_TEXT type fields reported as type STRING. #2753

Open
du8die opened this issue Dec 12, 2024 · 0 comments
Open

Rest API RICH_TEXT type fields reported as type STRING. #2753

du8die opened this issue Dec 12, 2024 · 0 comments

Comments

@du8die
Copy link

du8die commented Dec 12, 2024

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant