# Start a workflow from PayPal events

> Run a workflow when PayPal reports a payment, an order, a subscription change, or a dispute, with a Webhook block set to PayPal.

To run a workflow when PayPal reports a payment, an order, a subscription change, or a dispute, add a **Webhook** block whose **Source** is **PayPal** and give its URL to a webhook of your PayPal app. PayPal posts one event per request. Each event starts its own run.

You need a PayPal app whose webhooks you can open in the PayPal Developer Dashboard, and edit access to the workflow's project. The PayPal steps happen in PayPal's own dashboard.

## Add the Webhook block and generate its URL

1. In a draft workflow, add a **Webhook** block. The block palette also lists **PayPal webhook** in the **Start** group, which adds the block with its source already set.
2. Under **Source**, choose **PayPal**. The line under the setting reads "Verifies the signature · one run per event · skips duplicates".
3. Under **Webhook URL**, select **Generate URL**, then copy the URL.

The badge beside the URL reads "Runs start after publish". The URL contains a token, and anyone who has the URL can send requests to it. Keep it out of shared documents.

## Add the webhook in PayPal

1. In the PayPal Developer Dashboard, open **Apps & Credentials**, then your app.
2. In the app's webhooks, add a webhook, and paste the URL you copied as the address it sends to.
3. Choose the event types PayPal sends to this URL, and save the webhook.

PayPal sends a webhook only the events of the app that owns it. Add the webhook to the app your payments go through.

The Webhook block offers these PayPal event types: `PAYMENT.CAPTURE.COMPLETED`, `PAYMENT.CAPTURE.DENIED`, `PAYMENT.CAPTURE.PENDING`, `PAYMENT.CAPTURE.REFUNDED`, `PAYMENT.CAPTURE.REVERSED`, `CHECKOUT.ORDER.APPROVED`, `CHECKOUT.ORDER.COMPLETED`, `BILLING.SUBSCRIPTION.CREATED`, `BILLING.SUBSCRIPTION.ACTIVATED`, `BILLING.SUBSCRIPTION.CANCELLED`, `BILLING.SUBSCRIPTION.SUSPENDED`, `BILLING.SUBSCRIPTION.EXPIRED`, `BILLING.SUBSCRIPTION.PAYMENT.FAILED`, `CUSTOMER.DISPUTE.CREATED`, `CUSTOMER.DISPUTE.RESOLVED`, and `INVOICING.INVOICE.PAID`.

## Save the Webhook ID

PayPal signs each request with a certificate of its own, and the signature covers the id of the webhook the request was sent for. What you save in OutWin is that **Webhook ID**. It is an id, not a password: PayPal issues no secret for a webhook. The ID ties a request to this webhook: with it saved, a request that PayPal signed for another account's webhook does not pass.

1. In the PayPal Developer Dashboard, open **Apps & Credentials**, then your app. Under the app's webhooks, copy the **Webhook ID** shown beside the URL you added.
2. In OutWin, paste it into **Webhook ID** in the block's settings and select **Save**.

After you save, the settings show only the last four characters of the ID, with **Replace** and **Remove**. Under **Set up**, the second line changes to "The webhook ID is saved: deliveries are verified."

The ID belongs to one webhook, so OutWin saves it on the block's URL. It is not saved on a connection. A sandbox webhook and a live webhook are two webhooks with two IDs, so each needs its own Webhook block.

PayPal documents no limit on how old a signed request may be, and it sends a failed delivery again for up to three days, so OutWin checks no time on a request. A saved copy of a signed request that is sent again passes the check. If its event already ran in the last 72 hours, it is listed as **Duplicate** and starts no run. After that, it starts a run.

Without a saved ID the block still starts runs, and nothing is verified: anyone who has the URL can start the workflow. Publishing then shows a warning that ends "has no signing secret saved, so its deliveries are not verified: anyone who has this URL can start this workflow". The warning does not block publishing.

## Choose which events start a run

Under **Events that start a run**, tick the event types that start a run. With none ticked, every event PayPal sends starts a run. To start runs for a type that is not listed, type it into the box under the list and select **Add**.

An event whose type is not ticked is listed as **Filtered out** and starts no run. To narrow further by a field of the event, add a row under **Only when**. [Webhook settings](https://outwin.ai/docs/reference/triggers-approvals-and-waits/#webhook-settings) lists the comparisons.

## Send a test and check what arrived

1. In PayPal, cause one of the events the webhook sends, for example with a test payment through a sandbox app.
2. In OutWin, look under **Recent deliveries** in the block's settings.

**Recent deliveries** lists every event that reached the URL, including while the workflow is a draft. On a draft each event is listed as **Dropped** with "The workflow is not published, so nothing ran." It starts no run and is not run later. The last line under **Set up** changes from "Waiting for the first event…" to, for example, "Received PAYMENT.CAPTURE.COMPLETED. Dropped."

With an ID saved, an event listed as **Dropped** on a draft has passed the signature check. A delivery that fails the check is listed as **Refused**.

PayPal's webhooks simulator signs its events for the literal id `WEBHOOK_ID`, not for your webhook's ID. With your webhook's ID saved, a simulator event is listed as **Refused**. To try the block with the simulator, save `WEBHOOK_ID` as the **Webhook ID**, and replace it with your webhook's ID before you publish. A block left on `WEBHOOK_ID` verifies simulator events, and anyone who has a PayPal developer account and the block's URL can send those.

If you have edit access, select an event to see what the block passed on. The list is kept for seven days, and the data of the newest 20 events is kept.

## Read the event in the next block

Each run receives one PayPal event. An HTTP request block or a database block directly after the Webhook block reads it with these expressions. An AI block such as **Think** receives the whole value as its input.

| Expression | What it holds |
| --- | --- |
| `{{input.body}}` | The event as PayPal sent it, with the fields `id`, `event_type`, `create_time`, and `resource`. |
| `{{input.body.resource}}` | One field of the event: what the event is about, such as the payment or the subscription. Its own fields depend on the event type. Read any other field the same way. |
| `{{input.event.type}}` | The event's type, such as `PAYMENT.CAPTURE.COMPLETED`. It is the event's `event_type` field. |
| `{{input.event.id}}` | The event's id. It is the event's `id` field. |
| `{{input.event.time}}` | The event's time as an ISO 8601 date and time. It is read from the event's `create_time` field. |
| `{{input.delivery.verified}}` | `true` only when the signature was checked and passed. |

A block further along reads the same values through the Webhook block's name, as in `{{steps["PayPal"].body.resource}}` for a block named `PayPal`. [Data and context](https://outwin.ai/docs/reference/data-and-context/) describes what each block passes on.

## Publish and check the runs

[Publish the workflow](https://outwin.ai/docs/run/publish-and-start/). From then on, each event that passes the filter starts a run. On a published workflow the block's settings are read-only, and **Recent deliveries** is in the block's inspector. You can still replace the ID there.

| Outcome | What happened |
| --- | --- |
| **Ran** | The event started a run. |
| **Waiting** | 10 runs of the workflow are already active. The event starts a run when one of them ends. An event that waits longer than an hour is listed as **Dropped**. |
| **Duplicate** | An event with the same `id` already ran in the last 72 hours. The line reads "This event was already received and run, so it did not run again." |

Runs start in the order events arrive. That is not always the order things happened, so do not build a workflow that relies on `CHECKOUT.ORDER.APPROVED` arriving before `PAYMENT.CAPTURE.COMPLETED`.

Receiving an event costs no credits, and neither does an event that is filtered out or a duplicate. A run that starts uses credits for the blocks that run in it.

## If nothing runs

Open **Recent deliveries** and read the outcome and the sentence beside the newest event.

| What you see | Cause | Fix |
| --- | --- | --- |
| "Nothing has arrived yet." | No request has reached the URL. | Check that the webhook belongs to the app that produced the event, that it sends the event type you caused, and that its address is the block's current URL. **Rotate token** on a published workflow changes the URL, and the old one stops working. |
| **Dropped** with "The workflow is not published, so nothing ran." | The workflow is a draft. | Publish the workflow. Events that arrived before then are not run later. |
| **Dropped** with "The workflow is paused, so nothing ran." | The workflow is paused. | Resume the workflow. Events that arrived while it was paused are not run later. |
| **Filtered out** with `Events of type "PAYMENT.CAPTURE.PENDING" are not chosen on this trigger.` | The event's type is not ticked under **Events that start a run**. | Tick the type, or clear every tick so that all events start a run. The settings are read-only on a published workflow. |
| **Refused** with "The signature did not match. Check that the webhook ID saved here is the one PayPal shows for this URL." | The saved ID is not the ID of the webhook that sent the request. This happens when the ID was copied from another webhook, such as the sandbox one for a live URL, and when a simulator event reaches a block that has a real webhook's ID. | Copy the **Webhook ID** shown beside this URL in PayPal and select **Replace**. You do not republish the workflow. |
| **Refused** with "The saved webhook ID is not one PayPal issues. Save it again exactly as PayPal shows it." | The saved value has characters a webhook ID does not have, or is longer than 50 characters. Something other than the ID was pasted. | Copy the **Webhook ID** again and select **Replace**. |
| **Refused** with "The request carried no signature." | An ID is saved in OutWin, and the request did not carry PayPal's signature headers. A request sent by hand to try the URL has none. | Cause the event in PayPal so that PayPal sends the request. |
| **Refused** with "The request names a certificate that is not PayPal's." | The request points to a signing certificate at an address outside PayPal's API hosts. OutWin fetches the certificate only from those hosts. | Cause the event in PayPal so that PayPal sends the request. |
| **Refused** with "PayPal's certificate could not be fetched, so the signature could not be checked." | OutWin could not fetch the certificate the request names from PayPal. | Wait for PayPal to send the delivery again, or cause a new event. |

A delivery listed as **Refused** is answered with status `401` and starts nothing. OutWin keeps none of its data. PayPal sends a delivery that failed again for up to three days, so after you replace the ID, a later attempt of the same event can pass and start a run. For every other outcome in the table, PayPal receives a success response and OutWin does not run the event later.
