Webhook does not receive data from Amazing Marvin

Hi there!

I ran into a similar issue and stumbled on this thread, maybe you can help me out figure whats wrong with my setup: I recently tried editing a marketing automation webpage to add a custom script, it gets data from a database and prints it out to the user, getting as a parameter a JSON with the user e-mail.

Everything seems ok, the problem being I can’t POST to the webhook from the frontend regarding a CORS problem. And I know it’s something that is taken care by the web server and the reverse proxy and what not, but I’ve looked all over the forum and github pages and found out this: it’s possible to set the headers on the webhook node itself. You can see the merged pull request and discussions in the links below:

fix(core): Do allow OPTIONS requests from any source by janober · Pull Request #3555 · n8n-io/n8n (github.com)

Webhook does not receive data from Amazing Marvin - Questions - n8n

Override Accept Header in Http Request - Questions - n8n

It’s a bit confusing what we should use to allow these types of scenarios to work, and I’m lost on this. Here, let me show what I got so far:

It no longer gives me CORS errors related to the domain, instead it says this:

Access to fetch at ‘https://n8n.example.com/webhook-test/getInfo’ from origin ‘https://my.webpage.com’ has been blocked by CORS policy: Request header field content-type is not allowed by Access-Control-Allow-Headers in preflight response.

Even though I’ve added the header with a wildcard and also tried specifying “content-type” I couldn’t get it to work.

@Mikhail have you got around this issue? @jan can you share some light on this issue? Seems to me like they are the same.

1 Like

Request header field content-type is not allowed by Access-Control-Allow-Headers in preflight response

Hi @fogolin, preflight requests would be OPTIONS requests (MDN). n8n should answer these in general when sending a request to webhook URL:

However, there is no Access-Control-Allow-Headers in the repsonse at the moment which seems to be causing the problem here based on your error message. Perhaps it would make sense to add a Access-Control-Allow-Headers: * header as well, just like we did with the Access-Control-Allow-Origin one? I suppose this is more a feature request, but maybe @Jon can sneak these lines into the code next to the existing header when he next touches the webhook node :pleading_face:?

For now, you would indeed need to add these headers on the reverse proxy level. For caddy, the header directive should do the job (here’s an example from their forum), other web servers would have similar directives.

HI @fogolin ! I could not find a solution to the problem. I’m sorry I can’t help. If you are successful, please post here.

1 Like

So instead of adding “content-type” here I should use “*”? I believe I tried it before and couldn’t make it work neither… But if that’s the case, the way I’ve setup it here should work, right?

I’ll try again with the wildcard and post the results here, for this use case I actually went and made a REST API with php because of time constrains, but I’d like to use these resources within n8n in future projects.

Hi @fogolin, this would unfortunately not do the trick. Your webhook node lets you configure the response headers for the POST request, not the OPTIONS preflight request coming from your browser which causes the problem from the looks of it. So, this header would currently have to be added by a reverse proxy server.

And what is the solution?
Is here any chance to POST n8n webhooks from client-side???

Hey @orth, this is a rather old thread and I don’t have all details present anymore. Iirc you’d need to add the Access-Control-Allow-Headers: * header (or a more specific variation) on the reverse proxy level (so outside of n8n) for this to work.

Depending on the application you are using you could also consider using a different content type to avoid CORS as suggested here.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.