Problem with adding row with api

Hello

I have problem with request to add row i table. After POST reuest /index.php/apps/tables/api/1/tables/10/rows the response is:
“message”: “Column with id 0 is not part of table with id 10”

What’s wrong?

Hello,

I also get this message trying to add a new row via POST-Request.
The message is referring to
“colum with id 0”
allthough id 0 isn’t part of my request.

My data structure looks like this:

data ={
    "tableId": 11,
    "createdBy": "user",
    "createdAt": "2023-04-01 09:20:42",
    "lastEditBy": "user",
    "lastEditAt": "2023-04-01 09:20:42",
    "data": 
        {
        "columnId": 101,
        "value": {"Col1": "Tiger"} 
        }
}

Is there an error in my structure or could this be an API internal related issue?

I checked tableId and columnId. They are correct. GET request work just fine.

Maybe API documentation differs from actual requirements? Could 0 be used as default columnId value?

I am running tables V0.7 beta2 and used OCS API Viewer and Python for testing. Both ways leading to the same result.

Did others run into this message as well?

Hello,

I got the same error, too.

I did manage to perform all CRUD operations on Tables API from python. :white_check_mark:

Creation and Update data format is not so well documented on APIv1. :smirk:

« Data as key - value store »

How make it work in OCS API Viewer?

May be the Tables app is too joung?

The actual accepted data JSON to send format is: (mapped column id ==> data :woman_shrugging:)

data ={
    "data": 
        {
          "23": "Ivan",
          "24": "Dutest",
          "25": "ivan@invalid.email"
        }

}

:point_right:seen here

php code also duplicated here (Create/insert) :woman_shrugging: Seem joung code to me…

I’m currently developping a PoC on this Tables API for a project.

I could publish the python wrapper library under LGPL would you be intersted?

full working code:

EDIT :

import requests
import json
from dotenv import load_dotenv
import os

load_dotenv()  # take environment variables from .env.
username = "admin"
password = os.getenv('ADMIN_PASSWORD')
nextcloud_url = os.getenv('NEXTCLOUD_URL')

data ={
    "data":
        {
          "23": "Ivan",
          "24": "Dutest",
          "25": "ivan@invalid.email"
        }
}
tableId = 4
url_path = f"/index.php/apps/tables/api/1/tables/{tableId}/rows"
response = requests.post(
    f"{nextcloud_url}{url_path}",
    headers={
        "OCS-APIRequest": "true",
        'accept': 'application/json',
    },
    auth=(username, password),
    json=data,
    )

print(json.dumps(response.json(), indent=2))

Hello,

thank You @Sylvain2 .
Your post helped me a lot.

It could figure out how to make this work in OCS API Viewer:
The data field has to be structured like this:
{"314":"2024-05-28","101":"A123", "316":"https://nextcloud.com"}
This is equal to the structure of @Sylvain2 :

Date columnns have to be added with format “yyyy-mm-dd”
You can put simple hyperlinks in to that structure. See column ID 316.
In this case column 316 ist of type “link”.

If You want to have a proper hyperlink with custom title, You would have to nest the keys and values like this:

{"314":"2024-05-28","101":"A123","316":"{"title":"Link","providerId":"url","value":"https:\/\/nextcloud.com","subline":"URL"}"}

This would put a Hyperlink with title “Link” pointing to https://nextcloud.com into the new row for column with id 316.

Great it helped you @wunu

I stopped using Tables for my purpose. The code is definitively too young for production. But still under active development. Follow the git repos.

Advise: perform backup of your database. Plugin update did loose some development data. But you probably do that already, right? :wink:

Note: the JSON code sample you posted contains invalid UTF-8 chars…