Help

Upcoming database upgrades. Airtable functionality will be reduced for ~15 minutes at 06:00 UTC on Feb. 4 / 10:00 pm PT on Feb. 3. Learn more here

Re: Cannot make a post request with Airtable script

Solved
Jump to Solution
374 1
cancel
Showing results for 
Search instead for 
Did you mean: 

Hi,

I’m testing the script of Airtable and I’m facing the issue with POST request creation.

First, I tested my request with Postman and it worked fine.
image
image

Then I ran the same request with Airtable script and I got failed.

image

let response = await fetch('https://gorest.co.in/public/v2/users', {
    method: 'POST',
    body: {
        "name": "Tenali Ramakrishna",
        "gender": "male",
        "email": "tenali.ramakrishna2@15ce.com",
        "status": "active"
    },
    headers: {
        'Content-Type': 'application/json',
        "Accept": "application/json",
        "Authorization": "Bearer 84799e2274fa6626356d26d9364fde5320a5d3f1703b6d33a525a1585cbbce65",
    },
});
console.log(await response.json());

Could anyone help me on this? Thank you!

1 Solution

Accepted Solutions

Hey @Ngo_Hoang_Tuan,

you can’t use an object in the body field. You need to use JSON.stringify()

Here’s the updated script:


let body = {
        "name": "Tenali Ramakrishna",
        "gender": "male",
        "email": "tenali.ramakrishna2@15ce.com",
        "status": "active"
    }
let response = await fetch('https://gorest.co.in/public/v2/users', {
    method: 'POST',
    body: JSON.stringify(body),
    headers: {
        "Content-Type": "application/json",
        "Accept": "application/json",
        'Authorization': 'Bearer 84799e2274fa6626356d26d9364fde5320a5d3f1703b6d33a525a1585cbbce65',
    }, 
});
console.log(await response.json());

See Solution in Thread

2 Replies 2

Hey @Ngo_Hoang_Tuan,

you can’t use an object in the body field. You need to use JSON.stringify()

Here’s the updated script:


let body = {
        "name": "Tenali Ramakrishna",
        "gender": "male",
        "email": "tenali.ramakrishna2@15ce.com",
        "status": "active"
    }
let response = await fetch('https://gorest.co.in/public/v2/users', {
    method: 'POST',
    body: JSON.stringify(body),
    headers: {
        "Content-Type": "application/json",
        "Accept": "application/json",
        'Authorization': 'Bearer 84799e2274fa6626356d26d9364fde5320a5d3f1703b6d33a525a1585cbbce65',
    }, 
});
console.log(await response.json());

Awesome @Mariusz_S .

Thank you so much for your great support.