Jul 26, 2021 04:27 PM
I’m developing an API on Node.js + express on Heroku, and every time I fetch anything with POST, I get a 400 Bad request error.
Postman requests to the same endpoint work perfectly. So the only hypothesis I have is that I need a ‘Host’ header in my Airtable request (when I remove the ‘Host’ header in Postman. I get the same 400 Bad request error), but I don’t know what this ‘Host’ header should be.
To reproduce:
app.post('/', (request, response) => {
response.status(200).send(request.body);
})
let response = await fetch('https://....herokuapp.com/api/', {
method: 'POST',
body: JSON.stringify('Hello World!'),
headers: {
'Content-Type': 'application/json; charset=UTF-8',
'Accept': 'application/json'
},
});
console.log(await response.text());
You’ll get a ‘400 Bad Request’ response.
Solved! Go to Solution.
Jul 27, 2021 07:59 AM
Solved!
I had to add 'Host': 'https://*.airtableblocks.com'
header.
await remoteFetchAsync('https://....herokuapp.com/api/', {
method: 'POST',
body: requestBody,
headers: {
'Content-Type': 'application/json; charset=UTF-8',
'Host': 'https://*.airtableblocks.com',
'Accept': 'application/json'
},
})
Jul 27, 2021 07:59 AM
Solved!
I had to add 'Host': 'https://*.airtableblocks.com'
header.
await remoteFetchAsync('https://....herokuapp.com/api/', {
method: 'POST',
body: requestBody,
headers: {
'Content-Type': 'application/json; charset=UTF-8',
'Host': 'https://*.airtableblocks.com',
'Accept': 'application/json'
},
})