Error trying to do sql insert

I’m trying to insert a row through the API using SQL, but I am running into an error & not sure what I am doing wrong. Here is my sql statement:

"{""sql"":""insert into MyTable (Col1,Col2) values ('testvalue',123)"""

Col1 is a text field & Col2 is a number field. I get a response code 400 (Bad request) when I send the request. Can anyone help me out?

Seems you have too many quota in your SQL statement.

What programming language do you use to call the API?

I am using VB.net to call the API. And I am using that same string format when doing a Select, and it works fine, so I know that the quotes are correct:

"{""sql"":""select * from MyTable order by Date desc limit 1000"",""convert_keys"":true}"

Not sure why my insert won’t work. I am sending it to the API exactly the same way using the
HttpClient object in VB.Net.

Can anyone help me out? Anyone from SeaTable read these forums?

Anyone have any ideas?

I am not familiar with Visual Basic .NET, but there is an obvious difference between your SELECT and your INSERT statement: In the SELECT statement, you close the curly brackets. In the INSERT statement, you don’t.

And, yes, several SeaTable team members read and comment in the forum. Two have answered to your question at this point. We take the liberty of prioritizing responses based on the general relevance of the question and the way the question is asked.

You are correct, I was missing the closing curly brace in my insert statement, but that didn’t resolve the issue. I still get an error code 400.

Can you post an example in a different language, like maybe python, showing how to do an insert using the API? That might help me see what I need to do in VB.Net. Thank you.

Here is the short example for python:

from seatable_api import Base, context

api_token = context.api_token or "xxxxx"
server_url = context.server_url or "https://xxxx"

base = Base(api_token, server_url)
base.auth()
sql = """Insert into `TableName` (`colA`, `colB`) VALUES ('1', '2')"""
base.query(sql)

The codes is based on the seatable_api python package.
For the details , please refer to Rows - SeaTable Developer Manual

1 Like

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