Help

Re: [SOLVED] AWS API Gateway, CORS Errors and the Scripting Block

2241 0
cancel
Showing results for 
Search instead for 
Did you mean: 
Matt_Caruso
6 - Interface Innovator
6 - Interface Innovator

Hi everyone! This question touches on a lot of things outside of Airtable itself. Hoping someone here may have some insight.

I’m using the new Scripting Block to call an HTTP endpoint I’ve built using AWS API Gateway. A script runs in AWS Lambda and returns some data as JSON back to the Scripting Block to continue the workflow. For extra context, it’s a Lambda Proxy Integration.

I’m having trouble with CORS errors. I’m returning the CORS headers detailed here but still getting the error in Airtable.

Here’s the section of JS in the blocks where the call is being made:

// assemble the full URL from the record selection
let url = aws_url + record.getCellValueAsString("Project Record ID");
let headers = {
"Origin": "airtableblocks.com"
}
// make the API call
let response = await fetch(url, {
method: "GET",
headers: headers
})

Anyone have any similar experience?

5 Replies 5

Can you inspect the response using postman or something to be sure Access-Control-Allow-Origin: is really returning what you think it should be?

@openside is an expert on matters involving CORS and I think he recently spotted some issues with Script blocks.

Matthew_Thomas
7 - App Architect
7 - App Architect

This may be (un)intentional, but I was running into CORS issues myself trying to call an external API. My issue ultimately ended up being an HTTP vs. HTTPS problem that I detailed in this post.

In my case, my server wasn’t being pinged at all. First thing I would check is to see if the Lambda function is being run. If so, then my post probably doesn’t help. If not, as @Bill.French said, @openside probably has some ideas. Their contribution earlier in the thread helped me on the road to debugging.

Matt_Caruso
6 - Interface Innovator
6 - Interface Innovator

Thank you both! I was able to get this sorted out today.

It turns out I was missing some of the required CORS headers in API Gateway. I had to make sure I had all three of these included on the Method Response:

  "Access-Control-Allow-Origin": 
  "Access-Control-Allow-Methods": 
  "Access-Control-Allow-Headers":
openside
10 - Mercury
10 - Mercury

glad you got it worked out @Matt_Caruso.

and glad i’ve been deemed a CORS expert courtesy of @Bill.French. I should probably look up what CORS stands for so I can atleast fake that I know what I’m talking about there :slightly_smiling_face:

Save your energy. It stands for COntent Rejection Syndrome. :slightly_smiling_face: