Help

Re: Can't fetch from Node.js + express app on Heroku

Solved
Jump to Solution
1523 0
cancel
Showing results for 
Search instead for 
Did you mean: 
Alexey_Chekano1
5 - Automation Enthusiast
5 - Automation Enthusiast

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:

  1. Create a simple Node.js+express app on Heroku where you return the same body as you get:
app.post('/', (request, response) => {
 response.status(200).send(request.body);
})
  1. Create Airtable automation with fetch (or an app with remoteFetchAsync):
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.

1 Solution

Accepted Solutions
Alexey_Chekano1
5 - Automation Enthusiast
5 - Automation Enthusiast

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'
                    },
                })

See Solution in Thread

1 Reply 1
Alexey_Chekano1
5 - Automation Enthusiast
5 - Automation Enthusiast

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'
                    },
                })