0

I'm trying to insert data on my Postgresql DB but I failed.

So basically I can select the data with the query below;

curl 10.127.18.18:3001/mytable

I can get all rows with this request.

I tried pretty much combination of the commands below but all of them failed. How can I insert a basic data with postgREST?

"mytable" table has 2 columns, "user_id" and "username";

curl POST 10.127.18.18:3001/mytable { "user_id": 3333, "username": testuser }
curl -X POST 10.127.18.18:3001/mytable HTTP/1.1 { "user_id": "3333", "username": "testuser" }

Thanks!

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
yatta
  • 423
  • 1
  • 7
  • 22
  • Should work [just like that](https://postgrest.org/en/v3.2/api_writing.html). What error are you getting? – Bergi Jun 14 '21 at 09:28
  • Did you escape the http body as a string literal in the shell? – Bergi Jun 14 '21 at 09:29
  • Yes, I tried withoud HTTP body but still same "curl -X POST 10.127.17.72:3000/test1 { "user_id": "3333", "username": "testuser" }". Error is : curl: (3) unmatched brace in URL position 1: { ^ curl: (3) unmatched close brace/bracket in URL position 1: } ^ – yatta Jun 14 '21 at 09:32
  • That's not a postgres(t) error at all, but a curl usage error. What shell are you using? – Bergi Jun 14 '21 at 09:33
  • cygwin on windows. Even if I try on Ubuntu, I get similar errors. {"message":"Error in $: not enough input"}curl: (3) [globbing] unmatched brace at pos 2 curl: (6) Could not resolve host: user_id; Unknown error curl: (6) Could not resolve host: 3333,; Unknown error curl: (6) Could not resolve host: username; Unknown error curl: (6) Could not resolve host: testuser; Unknown error – yatta Jun 14 '21 at 09:42

1 Answers1

1

For those who encounter with the same problem, this query worked for me;

curl --location --request POST '10.127.18.18:3001/mytable' --header 'Content-Type: application/json' --data-raw '{  "user_id": "11", "username": "test"  }'
yatta
  • 423
  • 1
  • 7
  • 22