Softr database API: POST calls returning errors

Hey guys

Has anyone successfully managed to call the Softr database API recently? I’m stuck.

The GET calls seem to work just fine and return a list of records or single records:

curl -X GET 'https://tables-api.softr.io/api/v1/databases/<MY-DATABASE-ID>/tables/<MY-TABLE-ID>/records/<MY-RECORD-ID>' \
  -H 'Softr-Api-Key: <MY-API-KEY>'

Now when switching to a POST call, I only ever get “bad request” errors.

curl -X POST 'https://tables-api.softr.io/api/v1/databases/<MY-DATABASE-ID>/tables/<MY-TABLE-ID>/records/' \
  -H 'Softr-Api-Key: <MY-API-KEY>' -d '{ "fields": { "<MY-FIELD-ID>": "test" } }'

Error message:

{"message":"Bad request","errorCode":"BAD_REQUEST","details":{"traceId":<MY-TRACE-ID>}}

I tried to setup the same call directly in Softr and configure an action button to call the API, then I get a slightly different error message:

{"message":"Invalid payload","errorCode":"UNKNOWN_FIELD","details":{"<MY-FIELD-ID>":"Unrecognized field in request payload"}}

I double and triple checked the field-id: It exists in the table I’m calling and it’s spelled correctly. I validated through a GET request and copy-pasted the field-ID from the response but still no luck.

I’m out of ideas on what to try. Any suggestions?

Hi Christian, I think you need a PUT rather than a POST for updating records. Chris

Thanks Chris.

I try to create a new record through the API. The documentation says this is being done by a POST request.

Though I see where you are coming from: I accidentally have the record-id in the code snippet. That’s the mistake I did in the code snippet, but not in my test… I’ll update that, thanks!

1 Like

Hi! I realised after posting that you might have been trying to create but had the record-id in by accident. I’ll give more feedback in a dm, see if we can solve it.

Thanks Chris.

For documentation and so that others might be able to solve the issue a bit quicker. With an additional header, the API call through curl is now working:

curl -X POST 'https://tables-api.softr.io/api/v1/databases/<MY-DATABASE-ID>/tables/<MY-TABLE-ID>/records' \
  -H 'Softr-Api-Key: <MY-API-KEY>' \
  -H 'Content-Type: application/json' \
  -d '{ "fields": { "<MY-FIELD-ID>": "test" } }'

Maybe someone wants to add this to the official database API documentation? The code examples provided don’t feature this header.