API best practices with Carrd

Hi all - I wanted to know what folks would advise when connecting BR to services like custom forms in Carrd? Carrd allows you to add custom code to a form but it also offers to send the contents to a url via POST/GET or AJAX where you add in headers via their interface.

I’m struggling to get either working and I’m not sure if it’s something I’ve done (most likely) or if it’s a quirk about how Carrd takes/formats code.

Here’s what I’ve tried:
The fields are ‘Name’ and ‘Email’
1 - Custom code:

curl \
-X POST \
-H "Authorization: Token MYTOKEN" \
-H "Content-Type: application/json" \
"https://api.baserow.io/api/database/rows/table/TABLENUM/?user_field_names=true" \
--data '{
    "Name": document.forms[Name],
    "Email": document.forms[Email],
    "Active": true
}'

I’ve also tried:

POST https://api.baserow.io/api/database/rows/table/TABLENUM/?user_field_names=true HTTP
Authorization: Token MYTOKEN
Content-Type: application/json
{
    "Name": [Name],
    "Email": [Email],
}

2 - URL
https://api.baserow.io/api/database/rows/table/TABLENUM/?user_field_names=true

Method: AJAX
Format: tried both default and json

Under headers I added 2:
Authorization: Token TOKEN_ID
Content-Type: application/json

I know I’m most likely doing something blatantly wrong but just can’t figure it out. Thanks in advance if anyone has ideas :slight_smile:

Hi,

Do you get an error message from Carrd? It can be an authentication error that your token is not correct or does not have rights to create records. Or it can be an error message that the body content does not have the correct values.

You can also try with hard-coded values for Name and Email. Just the detect if it has something to do with passing the data to the body.

I can also recommend the tool Postman. It helps you to construct HTTP (API) requests and test if they are correct.

Thanks for the reply Frederik! When I open up the inspector it looks like it’s a 403 or 401 error depending on what I mess with. I have double-checked the token but will definitely try the hardcoded option to see if there’s an issue on that side of things. I might also try creating a new token and confirming it works with another service. Thanks for pointing out Postman - I’ll have a look at that as well.

401 = unauthorized and 403 = forbidden are related to each other.

The problem should be somewhere in the authentication. Make sure your token is preceded with the word Token followed by a space.

It was indeed. I don’t know why but when i created a new token, it worked! Thanks very much for your replies Frederik :slight_smile: