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

Can't add rows via API #1523

Open
mokkin opened this issue Jan 4, 2025 · 4 comments
Open

Can't add rows via API #1523

mokkin opened this issue Jan 4, 2025 · 4 comments
Labels
0. Needs triage Pending approval or rejection. This issue is pending approval. bug Something isn't working

Comments

@mokkin
Copy link

mokkin commented Jan 4, 2025

Steps to reproduce

I'm trying to write a row via API to a table. To achieve this I'm using the HTTP request node of n8n. No matter if I'm using the API v1 or v2 I can't successfully execute the command. In the log of Nextcloud I'm getting

[tables] Fehler: An internal error or exception occurred: Column with id 0 is not part of table with id 33
	POST /ocs/v2.php/apps/tables/api/2/tables/33/rows
	von 188.34.185.95 von demo um 04.01.2025, 21:20:19

This is the body I'm trying to send:

{
      "data": {
        "columnId": 233,
        "value": "Augusto"
      }
}

Other commands like GET /index.php/apps/tables/api/1/tables/33/columns are working and it can be clearly seen that table 33 has a column 233:

[
  {
    "id": 233,
    "tableId": 33,
    "title": "Name",
    "createdBy": "demo",
    "createdByDisplayName": "demo",
    "createdAt": "2025-01-04 00:49:00",
    "lastEditBy": "demo",
    "lastEditByDisplayName": "demo",
    "lastEditAt": "2025-01-04 00:49:00",
    "type": "text",
    "subtype": "line",
    "mandatory": false,
    "description": "",
    "numberDefault": null,
    "numberMin": null,
    "numberMax": null,
    "numberDecimals": 0,
    "numberPrefix": "",
    "numberSuffix": "",
    "textDefault": "",
    "textAllowedPattern": null,
    "textMaxLength": null,
    "selectionOptions": [],
    "selectionDefault": null,
    "datetimeDefault": null,
    "usergroupDefault": [],
    "usergroupMultipleItems": false,
    "usergroupSelectUsers": false,
    "usergroupSelectGroups": false,
    "showUserStatus": false
  }
]

The same with GET /index.php/apps/tables/api/1/tables/33/rows

[
  {
    "id": 3024,
    "tableId": 33,
    "createdBy": "demo",
    "createdAt": "2025-01-04 00:51:53",
    "lastEditBy": "demo",
    "lastEditAt": "2025-01-04 00:51:53",
    "data": [
      {
        "columnId": 233,
        "value": "Paulo"
      }
    ]
  }
]

Expected behavior

Write the row.

Actual behavior

No line is written.

Tables app version

0.8.2

Browser

Firefox 133.0.3

Client operating system

Manjaro Linux

Operating system

Ubuntu 22.04

Web server

Apache

PHP engine version

PHP 8.2

Database

MariaDB

Additional info

No response

@mokkin mokkin added 0. Needs triage Pending approval or rejection. This issue is pending approval. bug Something isn't working labels Jan 4, 2025
@mokkin
Copy link
Author

mokkin commented Jan 6, 2025

I don't know why, but with this escaped expression it is working:

{"data":   "{\"233\":\"Augusto\"}" }

Shouldn't be like that, or?

@blizzz
Copy link
Member

blizzz commented Jan 6, 2025

I don't know why, but with this escaped expression it is working:

{"data":   "{\"233\":\"Augusto\"}" }

Shouldn't be like that, or?

Now in this example you need to escape it, otherwise you already have open double quotes.

In the holidays i did some stuff and never had an issues with creating rows: https://codeberg.org/blizzz/fahrplan2tables/src/branch/main/src/Domain/Tables/Manager.php#L51-L57

Might be n8n is doing something there? 🤷

@mokkin
Copy link
Author

mokkin commented Jan 6, 2025

Might be n8n is doing something there? 🤷

To check this I tried with curl and I'm getting the same result:

 curl -X 'POST' -u demo:'password'\
  'https://wolke.netzinstitut.de/ocs/v2.php/apps/tables/api/2/tables/33/rows' \
  -H 'accept: application/json' \
  -H 'OCS-APIRequest: true' \
  -H 'Content-Type: application/json' \
  -d '{
      "data": {
        "columnId": 233,
        "value": "Augusto"
      }
}'
{"ocs":{"meta":{"status":"failure","statuscode":500,"message":""},"data":{"message":"Es ist ein unerwarteter Fehler aufgetreten. Weitere Details findest du in den Protokollen. Bitte wende dich an deine Administration."}}}%   
[tables] Fehler: An internal error or exception occurred: Column with id 0 is not part of table with id 33
	POST /ocs/v2.php/apps/tables/api/2/tables/33/rows
	von 79.232.240.58 von demo um 06.01.2025, 19:33:32

Using the escaped format works as well:

curl -X 'POST' -u demo:'password'\
  'https://wolke.netzinstitut.de/ocs/v2.php/apps/tables/api/2/tables/33/rows' \
  -H 'accept: application/json' \
  -H 'OCS-APIRequest: true' \
  -H 'Content-Type: application/json' \
  -d '{"data":   "{\"233\":\"Augusto\"}" }'
{"ocs":{"meta":{"status":"ok","statuscode":200,"message":"OK"},"data":{"id":3030,"tableId":33,"createdBy":null,"createdAt":null,"lastEditBy":null,"lastEditAt":null,"data":[{"columnId":233,"value":"Augusto"}]}}}%

@blizzz
Copy link
Member

blizzz commented Jan 6, 2025

It's not an issue on our side (endpoint are also used from the web ui, for instance). Perhaps try --data-binary, `--json' or such with curl when passing the data to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0. Needs triage Pending approval or rejection. This issue is pending approval. bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants