***

title: Create an event subscription
icon: bell
published: true
intro: Receive notifications when events occur.
---------------------

For clean Markdown of any page, append .md to the page URL. For a complete documentation index, see https://docs.payroc.com/full-stack-guides/board-merchants/event-subscriptions/llms.txt. For full documentation content, see https://docs.payroc.com/full-stack-guides/board-merchants/event-subscriptions/llms-full.txt.

To add event notifications to your integration, use our API to create an event subscription and handle the notification that we send by webhook when an event occurs.

<Warning>
  **Important:** To receive notifications, your server must be able to handle POST requests.
</Warning>

To create an event subscription, send the following information in your request:

* **Event type** - The event that you want to subscribe to. You can subscribe to more than one event within the same request.
* **URI** - The endpoint that we send notifications to. The endpoint must be publicly available.
* **Secret** - A secret that we return in the header of webhook requests to verify that it is a genuine request.
* **Event status** - The status of the event subscription.
* **Email address** - An email address that we contact if we can't communicate with the endpoint that you provided.

<Note>
  **Note:** For a complete list of events that you can subscribe to, go to [Events list](/knowledge/events).
</Note>

## Integration steps

**Step 1.** Create an event subscription\
**Step 2.** Send a 200 response code\
**Step 3.** Handle the notification content

## Before you begin

### Bearer tokens

Use our Identity Service to generate a Bearer token to include in the header of your requests. To generate your Bearer token, complete the following steps:

1. Include your API key in the x-api-key parameter in the header of a POST request.
2. Send your request to [https://identity.payroc.com/authorize](https://identity.payroc.com/authorize).

<Note>
  **Note:** You need to generate a new Bearer token before the previous Bearer token expires.
</Note>

#### Example request

```bash
curl --location --request POST 'https://identity.payroc.com/authorize' --header 'x-api-key: <api key>'
```

#### Example response

If your request is successful, we return a response that contains your Bearer token, information about its scope, and when it expires.

```json
{
  "access_token": "eyJhbGc....adQssw5c",
  "expires_in": 3600,
  "scope": "service_a service_b",
  "token_type": "Bearer"
}
```

### Headers

To create the header of each POST request, you must include the following parameters:

* **Content-Type:** Include application/json as the value for this parameter.
* **Authorization:** Include your Bearer token in this parameter.
* **Idempotency-Key:** Include a UUID v4 to make the request idempotent.

```bash
curl
  -H "Content-Type: application/json"
  -H "Authorization: <Bearer token>"
  -H "Idempotency-Key: <UUID v4>"
```

### Errors

If your request is unsuccessful, we return an error. For more information about errors, see [Errors](/api/errors).

## Step 1. Create an event subscription

To create an event subscription, send a POST request to our event subscriptions endpoint.

| Endpoint   | Prefix     | URL                                                                                                    |
| :--------- | :--------- | :----------------------------------------------------------------------------------------------------- |
| Test       | `api.uat.` | [https://api.uat.payroc.com/v1/event-subscriptions](https://api.uat.payroc.com/v1/event-subscriptions) |
| Production | `api.`     | [https://api.payroc.com/v1/event-subscriptions](https://api.payroc.com/v1/event-subscriptions)         |

### Request parameters

To create the body of your request, use the following parameters:

<EndpointSchemaSnippet endpoint="POST /event-subscriptions" selector="request.body" />

### Example request

<EndpointRequestSnippet endpoint="POST /event-subscriptions" />

### Response fields

If your request is successful, we send you the ID of the subscription. You can use the ID to update, retrieve, or delete the event subscription.

The response contains the following fields:

<EndpointSchemaSnippet endpoint="POST /event-subscriptions" selector="response.body" />

### Example response

<EndpointResponseSnippet endpoint="POST /event-subscriptions" example="createdEventSubscription" />

## Step 2. Send a 200 response code

We send notifications by webhook request to the URI endpoint that you provided when you created the subscription.

You must return a 200 status code when you receive the request.

If we do not receive a 200 response, we retry the request five times. After the fifth attempt, we send an email to the support email address that you provided when you created the subscription.

<Note>
  **Note:** We send an email only when a single instance of an event notification fails to deliver. If the event occurs again, we send another notification.
</Note>

## Step 3. Handle the notification content

Each notification follows the [CloudEvents](https://cloudevents.io/) standard, and we use the data object to communicate information about the event that occurred, for example:

```json
{
  "specversion": "1.0",
  "type": "processingAccount.status.changed",
  "version": "1.0",
  "source": "payroc",
  "id": "123e4567-e89b-12d3-a456-426614174000",
  "time": "2024-07-02T15:30:00.000Z",
  "datacontenttype": "application/json",
  "data": {
    "processingAccountId": "38765",
    "status": "entered"
  }
}
```

You can view our event notifications on the [Events](/knowledge/events) page.