Feb 17, 2022 04:10 AM
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.
Then I ran the same request with Airtable script and I got failed.
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!
Solved! Go to Solution.
Feb 17, 2022 11:18 AM
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());
Feb 17, 2022 11:18 AM
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());
Feb 17, 2022 06:34 PM
Awesome @Mariusz_S .
Thank you so much for your great support.