最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Zapier Webhooks and AJAX Requests - Stack Overflow

programmeradmin4浏览0评论

Is there a way of triggering Zapier webhooks from client-side applications?

I can't seem to make successful AJAX requests and always get:

XMLHttpRequest cannot load /..... 
The request was redirected to '/..../', 
which is disallowed for cross-origin requests that require preflight. 

Is there a way of triggering Zapier webhooks from client-side applications?

I can't seem to make successful AJAX requests and always get:

XMLHttpRequest cannot load https://zapier.com/hooks/catch/..... 
The request was redirected to 'https://zapier.com/hooks/catch/..../', 
which is disallowed for cross-origin requests that require preflight. 
Share Improve this question edited Feb 22, 2021 at 1:07 mewc 1,4471 gold badge18 silver badges27 bronze badges asked Jul 3, 2014 at 9:53 BarakChamoBarakChamo 3,5757 gold badges32 silver badges39 bronze badges
Add a comment  | 

6 Answers 6

Reset to default 11

You must not modify the Content-Type header

https://zapier.com/help/create/code-webhooks/troubleshoot-webhooks-in-zapier#posting-json-from-web-browser-access-control-allow-headers-in-preflight-response-error

As of January 15th, 2016, Zapier does not support catching a webhook using a POST request from a browser (due to CORS headers required for the browser's preflight request).

A GET request with query string values will work though.

Zapier does not support CORS. The way I got this to work was to use an image.

var newImage = new Image();
newImage.src = "https://zapier.com/hooks/catch/myhook?param=one";

or

<img height="0" width="0" src="https://zapier.com/hooks/catch/myhook?param=one">

This works for me:

  try {
    var xhr = new XMLHttpRequest();
    xhr.open("POST", "https://zapier.com/hooks/catch/myhook");
    xhr.send(JSON.stringify({data: "example"}));
    console.log("Pushed to Zapier successfully!");
  } catch(e) {
    console.error(e);
  }

Using a Fetch request without setting the Content-Type also works,

const response = await fetch(
`https://hooks.zapier.com/hooks/catch/${code}/${code}`,
    {
  method: 'POST',
  body: JSON.stringify(payload)
    }

Zapier's awesome support team fixed CORS issue in under 24 hours!

Kudos Zapier!

发布评论

评论列表(0)

  1. 暂无评论