Help

Cannot make a post request with Airtable script

Topic Labels: Scripting extentions
Solved
Jump to Solution
4784 2
cancel
Showing results for 
Search instead for 
Did you mean: 
Ngo_Hoang_Tuan
5 - Automation Enthusiast
5 - Automation Enthusiast

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
Mariusz_S
7 - App Architect
7 - App Architect

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
Mariusz_S
7 - App Architect
7 - App Architect

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.