Create an event subscription

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.
Important: To receive notifications, your server must be able to handle POST requests.
To create an event subscription, send the following information in your request:
  • Event type - The event that you want to subscribe to. You can subsribe 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: For a complete list of events that you can subscribe to, go to Events list.

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.
You need to generate a new Bearer token before the previous Bearer token expires.

Example request

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.
{
"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.
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.

Step 1. Create an event subscription

To create an event subscription, send a POST request to our event subscriptions endpoint. Test endpoint: https://api.uat.payroc.com/v1/event-subscriptions
Production endpoint: https://api.payroc.com/v1/event-subscriptions

Request parameters

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

Header parameters

Body parameters

Example request

Request
curl --request post \
--url https://api.payroc.com/v1/event-subscriptions \
--header 'Authorization: Bearer <access token>' \
--header 'Content-Type: application/json' \
--header 'Idempotency-Key: 8e03978e-40d5-43e8-bc93-6894a57f9324' \
--data '{"enabled":true,"eventTypes":["processingAccount.status.changed"],"notifications":[{"type":"webhook","uri":"https://my-server/notification/endpoint","secret":"aBcD1234eFgH5678iJkL9012mNoP3456","supportEmailAddress":"[email protected]"}],"metadata":{"yourCustomField":"abc123"}}'

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:

Response Schema

Status Code 201

Successful request. We created the event subscription.
Response headers
Response body

Example response

Response
application/json
{
"id": 2565435189324,
"enabled": true,
"status": "registered",
"eventTypes": [
"processingAccount.status.changed"
],
"notifications": [
{
"type": "webhook",
"uri": "https://my-service/notification/endpoint",
"secret": "**********NoP3456",
"supportEmailAddress": "[email protected]"
}
],
"metadata": {
"yourCustomField": "abc123"
}
}

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: 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.

Step 3. Handle the notification content

Each notification follows the CloudEvents standard, and we use the data object to communicate information about the event that occurred, for example:
{
"specversion": "1.0",
"type": "processingAccount.status.changed",
"version": "1.0"
"source": "payroc",
"id": "123e4567-e89b-12d3-a456-426614174000",
"time": "2024-05-12T12:34:56.789Z",
"datacontenttype": "application/json",
"data": {
"processingAccountId": "12345678",
"status": "entered"
}
}
You can view our event notifications on the Events page.