# Problem with adding row with api

**URL:** <https://help.nextcloud.com/t/problem-with-adding-row-with-api/186696>\
**Category:** ℹ️ Support\
**Tags:** tables-app\
**Created:** [March 29, 2024, 3:07pm UTC](https://help.nextcloud.com/t/problem-with-adding-row-with-api/186696 "2024-03-29T15:07:58Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Damian\_Kulikowski](https://help.nextcloud.com/user_avatar/help.nextcloud.com/damian_kulikowski/32/58550_2.png) [@Damian\_Kulikowski](https://help.nextcloud.com/u/Damian_Kulikowski)\
**Post date:** [March 29, 2024, 3:07pm UTC](https://help.nextcloud.com/t/problem-with-adding-row-with-api/186696/1 "2024-03-29T15:07:58Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![wunu](https://help.nextcloud.com/letter_avatar/wunu/32/6_449c533f586939b6e5f246632a46421f.png) [@wunu](https://help.nextcloud.com/u/wunu)\
**Post date:** [April 8, 2024, 7:52pm UTC](https://help.nextcloud.com/t/problem-with-adding-row-with-api/186696/2 "2024-04-08T19:52:42Z")

</div>

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:

```auto
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?

---

<div class="post-metadata">

**Author:** ![Sylvain2](https://help.nextcloud.com/letter_avatar/sylvain2/32/6_449c533f586939b6e5f246632a46421f.png) [@Sylvain2](https://help.nextcloud.com/u/Sylvain2)\
**Post date:** [April 26, 2024, 9:07am UTC](https://help.nextcloud.com/t/problem-with-adding-row-with-api/186696/3 "2024-04-26T09:07:58Z")

</div>

Hello,

I got the same error, too.

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

Creation and Update data format is not so well documented on [APIv1](https://petstore.swagger.io/?url=https://raw.githubusercontent.com/nextcloud/tables/main/openapi.json#/api1/api1-update-row). 😏

> « 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 🤷‍♀️)

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

}

```

👉[seen here](https://github.com/nextcloud/tables/blob/main/lib/Controller/Api1Controller.php#L1195)

php [code also duplicated here](https://github.com/nextcloud/tables/blob/main/lib/Controller/Api1Controller.php#L1115) (Create/insert) 🤷‍♀️ 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 :

```python
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))

```

---

<div class="post-metadata">

**Author:** ![wunu](https://help.nextcloud.com/letter_avatar/wunu/32/6_449c533f586939b6e5f246632a46421f.png) [@wunu](https://help.nextcloud.com/u/wunu)\
**Post date:** [June 12, 2024, 7:54pm UTC](https://help.nextcloud.com/t/problem-with-adding-row-with-api/186696/4 "2024-06-12T19:54:00Z")

</div>

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](https://nextcloud.com) into the new row for column with id 316.

---

<div class="post-metadata">

**Author:** ![Sylvain2](https://help.nextcloud.com/letter_avatar/sylvain2/32/6_449c533f586939b6e5f246632a46421f.png) [@Sylvain2](https://help.nextcloud.com/u/Sylvain2)\
**Post date:** [June 18, 2024, 11:19am UTC](https://help.nextcloud.com/t/problem-with-adding-row-with-api/186696/5 "2024-06-18T11:19:55Z")

</div>

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? 😉

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

---

<div class="post-metadata">

**Author:** ![system](https://help.nextcloud.com/user_avatar/help.nextcloud.com/system/32/29333_2.png) [@system](https://help.nextcloud.com/u/system)\
**Post date:** [September 16, 2024, 11:20am UTC](https://help.nextcloud.com/t/problem-with-adding-row-with-api/186696/6 "2024-09-16T11:20:41Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
