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

🐛 Bug: Update base with meta data via API doesn't work #8417

Open
1 task done
salim-b opened this issue May 6, 2024 · 1 comment
Open
1 task done

🐛 Bug: Update base with meta data via API doesn't work #8417

salim-b opened this issue May 6, 2024 · 1 comment

Comments

@salim-b
Copy link
Contributor

salim-b commented May 6, 2024

Please confirm if bug report does NOT exist already ?

  • I confirm there is no existing issue for this

Steps to reproduce ?

Issue the following HTTP request to update a base with the provided meta data:

curl -X 'PATCH' \
  'https://api.example.com/api/v2/meta/bases/{baseId}' \
  -H 'xc-token: abcd1234' \
  -H 'Content-Type: application/json' \
  -d '{ "meta": { "showNullAndEmptyInFilter": true } }'

(replace URL and xc-token with actual values, of course)

Although the request is answered with a HTTP 200 (with the value 1 in the response body), it has not the intended effect, i.e. it does not enable the "Show NULL & Empty in Filters" base setting.

Instead, the next time the NocoDB UI is reloaded, the following error message is displayed, indicating that something went wrong:

JSON.parse: unexpected character at line 1 column 2 of the JSON data

Desired Behavior

The base settings should be configured according to the meta data in the HTTP request.

Project Details

Node: v20.11.1
Arch: x64
Platform: linux
Docker: false
RootDB: sqlite3
PackageVersion: 0.207.0

Attachments

No response

@salim-b
Copy link
Contributor Author

salim-b commented May 27, 2024

Further observations related to this issue, i.e. how peculiarly NocoDB handles a base's meta field:

  • A call to the PATCH /api/v2/meta/bases/{base_id} API endpoint to update a base incl. the meta field succeeds (meaning the result is properly parsed by the server) iff

    1. meta is specified as a character scalar instead of an actual JSON object, and
    2. meta.iconColor is included.

    Working example:

    curl -X 'PATCH' \
      'https://api.example.com/api/v2/meta/bases/{baseId}' \
      -H 'xc-token: abcd1234' \
      -H 'Content-Type: application/json' \
      -d '{ "meta": "{\"iconColor\":\"#3f4eff\",\"showNullAndEmptyInFilter\":true}" }'
  • The POST /api/v2/meta/bases API endpoint to create a new base OTOH accepts meta as a regular JSON object and the result is properly interpreted by the server AFAICT.

    After creating a new base this way, the GET /api/v2/meta/bases/{base_id} API endpoint to retrieve an existing base returns the meta field as a JSON object (like the rest of the JSON body).

    This is what one would expect.

  • When config encoded in the meta field is changed via the NocoDB UI, NocoDB seems to store the updated meta config as a character scalar instead of a JSON object. This can be verified by first creating a new base as outlined above, then changing e.g. the base's icon color and finally calling the GET /api/v2/meta/bases/{base_id} endpoint – the meta field in the response body is now a character scalar (containing valid JSON syntax) instead of an actual JSON object.

    On page reload, NocoDB seems to attempt to parse a base's meta field (and throws a JSON.parse error if that fails for some reason).

Why is handling the meta field implemented in this way (writing and parsing JSON text instead of directly using actual JSON)? Besides making it hard to use NocoDB's RESTful API, this also unnecessarily complicates development, I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🏌️ Open
Development

No branches or pull requests

1 participant