> For clean Markdown content of this page, append .md to this URL. For the complete documentation index, see https://learning.postman.com/llms.txt. For full content including API reference and SDK examples, see https://learning.postman.com/llms-full.txt.

# Trigger collection runs using webhooks

A webhook provides a way to automatically send data from one application to another. Using the Postman API's POST `/webhooks` endpoint, you can create a webhook for a collection. This creates a monitor that runs the collection when the webhook is triggered at a specific time or when an event occurs.

You can also send a custom payload to the webhook, and Postman can access the data when the collection runs. This means you can run a collection without an environment, and instead rely on the data sent to the webhook.

## Create a webhook

With a collection webhook, data is sent to the webhook URL using a POST request when certain events are triggered. You must configure the application that sends the data and the trigger events. Webhooks for a collection must be created using the [Postman API](/docs/reference/postman-api/intro-api/). Learn how to use the Postman API to [create a webhook](https://www.postman.com/postman/postman-public-workspace/request/z961fuf/create-a-webhook).

To access the data sent to the webhook, use the [`pm.globals.get` method](/docs/tests-and-scripts/write-scripts/postman-sandbox-reference/pm-variables/#pmglobals) with the `previousRequest` global variable. Using [scripts](/docs/tests-and-scripts/write-scripts/intro-to-scripts/), you can parse that data and use it during the collection run in any way possible.

## Access the request body in scripts

When you trigger the webhook, the `previousRequest` global [variable](/docs/use/send-requests/variables/variables/) is temporarily created, and its value is the request body of the webhook as a JSON string. Use the `pm.globals.get('previousRequest')` method to get the request body of the webhook, then parse it using `JSON.parse()`. The data sent to the webhook is available in the `data` parameter inside the parsed object, as shown in the following example code:

```js
var previousRequest = JSON.parse(pm.globals.get('previousRequest'));

var webhookRequestData = previousRequest.data;

// webhookRequestData contains the data sent to your webhook.
console.log(JSON.stringify(webhookRequestData));
```

The request body sent to the webhook must use JSON format.

When you [create a webhook](#create-a-webhook) using the Postman API, a monitor is created for the webhook. You must trigger the webhook in a separate request to run the example code using the monitor. Then you can [view the monitor run details](/docs/monitoring-your-api/viewing-monitor-results/#console-log) that were logged to Console. To learn more about monitor results, see [View monitor results](/docs/monitoring-your-api/viewing-monitor-results/).

## Send output to another API

Use the data that's sent to the collection webhook to define logic and trigger another API. For example, you might set up a webhook for your GitHub repository. Based on the updates happening in your repository, you can use the webhook to run custom build pipelines or perform CI tests.