> For the complete documentation index, see [llms.txt](https://docs.rewst.help/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.rewst.help/documentation/automations/intro-to-triggers/use-cases-and-examples/configure-a-webhook-trigger-for-cors-requests.md).

# Configure a webhook trigger for CORS requests

{% hint style="info" %}
Though this is related to triggers, it's most often used in conjunction with App Builder. Learn more about Rewst's App Builder in our documentation [here](/documentation/app-builder.md).
{% endhint %}

## What is a CORS request?

When referencing a Rewst web hook in JavaScript in an App Builder page— or outside of Rewst— you may see the error `TypeError: Failed to fetch.` This happens when the browser blocks your request because it does not allow *cross-origin* requests by default.

To make your webhook accessible from a web page, you must configure *CORS (Cross-Origin Resource Sharing)* headers and enable OPTIONS requests on your webhook.

{% hint style="info" %}
Note that **wait for webhook** cannot be set to `true` for this to work. Additionally, this webhook shouldn't use a secret key.
{% endhint %}

## Add CORS headers to your web hook response

1. Open your webhook trigger inside the workflow.
2. Click ![](https://1835401289-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAQQ1EHVcEsGKBPVHmiav%2Fuploads%2F9PoBcOyad2W0qySvSn5Q%2FScreenshot%202026-04-20%20at%203.41.07%E2%80%AFPM.png?alt=media\&token=3f0a5060-d67f-4357-8626-0fe44bc88ba0) to open the response headers code editor.
3. Add the following headers:

```django
{
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "https://YOURDOMAINHERE",
"Access-Control-Allow-Methods": "POST, GET, OPTIONS",
"Access-Control-Allow-Headers": "Content-Type"
}
```

<figure><img src="https://1835401289-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAQQ1EHVcEsGKBPVHmiav%2Fuploads%2FFICe9KR9gJKs1QJhLibA%2FScreenshot%202026-04-20%20at%203.42.34%E2%80%AFPM.png?alt=media&amp;token=a67e79a3-3951-4c5d-b2a2-9bde88b5eaaa" alt=""><figcaption></figcaption></figure>

{% hint style="warning" %}
**Important -** Match the *exact* origin of your site.

> ✅ <https://bclimer-cors-test.rew.st>

> ❌ <https://bclimer-cors-test.rew.st/>

Avoid using \* unless the webhook is fully public and returns no sensitive data.
{% endhint %}

## Reference table

| Header                       | Description                              | Example                            |
| ---------------------------- | ---------------------------------------- | ---------------------------------- |
| Access-Control-Allow-Origin  | Defines which site may call your webhook | <https://your-frontend-domain.com> |
| Access-Control-Allow-Methods | Lists allowed HTTP verbs                 | GET, POST, OPTIONS                 |
| Access-Control-Allow-Headers | Lists allowed custom headers             | Content-Type                       |
| OPTIONS                      | Preflight permission check               | Must return 200 with headers       |

## Handle OPTIONS preflight requests

Browsers send an *OPTIONS* request before certain POST or PUT requests to confirm that CORS is allowed. Your webhook must allow OPTIONS requests for this to succeed.

Add OPTIONS under the **Allowed Methods** field of your **Trigger Parameters** menu in workflow setting&#x73;**.**

<figure><img src="https://1835401289-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAQQ1EHVcEsGKBPVHmiav%2Fuploads%2FFmkBAhQAWnhPVhXxppRt%2FScreenshot%202026-04-20%20at%203.43.36%E2%80%AFPM.png?alt=media&amp;token=76f02bef-a6ea-448d-836f-52b66503f4ce" alt=""><figcaption></figcaption></figure>

## Troubleshoot the CORS webhook trigger

#### Trailing slash in origin

Try removing the slash from the end of your domain.

#### Missing OPTIONS handler

Add the OPTIONS method to the webhook.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.rewst.help/documentation/automations/intro-to-triggers/use-cases-and-examples/configure-a-webhook-trigger-for-cors-requests.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
