> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.payroc.com/llms.txt.
> For full documentation content, see https://docs.payroc.com/llms-full.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.payroc.com/_mcp/server.

# Create event subscription

POST https://api.payroc.com/v1/event-subscriptions
Content-Type: application/json

Use this method to create an event subscription that we use to notify you when an event occurs, for example, when we change the status of a processing account.  

In the request, include the events that you want to subscribe to and the public endpoint that we send event notifications to. For a complete list of events that you can subscribe to, go to [Events List](https://docs.payroc.com/knowledge/events/events-list).  

In the response, our gateway returns the id of the event subscription, which you can use to perform follow-on actions.  


Reference: https://docs.payroc.com/api/schema/notifications/event-subscriptions/create

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: Payroc API
  version: 1.0.0
paths:
  /event-subscriptions:
    post:
      operationId: create
      summary: Create event subscription
      description: >
        Use this method to create an event subscription that we use to notify
        you when an event occurs, for example, when we change the status of a
        processing account.  


        In the request, include the events that you want to subscribe to and the
        public endpoint that we send event notifications to. For a complete list
        of events that you can subscribe to, go to [Events
        List](https://docs.payroc.com/knowledge/events/events-list).  


        In the response, our gateway returns the id of the event subscription,
        which you can use to perform follow-on actions.  
      tags:
        - subpackage_notifications.subpackage_notifications/eventSubscriptions
      parameters:
        - name: Authorization
          in: header
          description: Bearer authentication
          required: true
          schema:
            type: string
        - name: Idempotency-Key
          in: header
          description: >-
            Unique identifier that you generate for each request. You must use
            the [UUID v4 format](https://www.rfc-editor.org/rfc/rfc4122) for the
            identifier. For more information about the idempotency key, go to
            [Idempotency](https://docs.payroc.com/api/idempotency).
          required: true
          schema:
            type: string
            format: uuid
      responses:
        '201':
          description: Successful request. We created the event subscription.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/eventSubscription'
        '400':
          description: Validation error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/400'
        '401':
          description: Identity could not be verified
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/401'
        '404':
          description: Resource not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/404'
        '406':
          description: Not acceptable
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/406'
        '409':
          description: Conflict
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/409'
        '500':
          description: An error has occured
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/500'
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/eventSubscription'
servers:
  - url: https://api.payroc.com/v1
    description: Production
  - url: https://api.uat.payroc.com/v1
    description: UAT
components:
  schemas:
    '400':
      type: object
      properties:
        type:
          type: string
          description: URI reference identifying the problem type
        title:
          type: string
          description: Short description of the issue.
        status:
          type: integer
          description: Http status code
        detail:
          type: string
          description: Explanation of the problem
        errors:
          type: array
          items:
            $ref: '#/components/schemas/ErrorsItems'
      required:
        - type
        - title
        - status
        - detail
      title: '400'
    '401':
      type: object
      properties:
        type:
          type: string
          description: URI reference identifying the problem type
        title:
          type: string
          description: Short description of the issue.
        status:
          type: integer
          description: Http status code
        detail:
          type: string
          description: Explanation of the problem
      required:
        - type
        - title
        - status
        - detail
      title: '401'
    '404':
      type: object
      properties:
        type:
          type: string
          description: URI reference identifying the problem type
        title:
          type: string
          description: Short description of the issue.
        status:
          type: integer
          description: Http status code
        detail:
          type: string
          description: Explanation of the problem
        resource:
          type: string
          description: Resource that was not found
      required:
        - type
        - title
        - status
        - detail
      title: '404'
    '406':
      type: object
      properties:
        type:
          type: string
          description: URI reference identifying the problem type
        title:
          type: string
          description: Short description of the issue.
        status:
          type: integer
          description: Http status code
        detail:
          type: string
          description: Explanation of the problem
      required:
        - type
        - title
        - status
        - detail
      title: '406'
    '409':
      type: object
      properties:
        type:
          type: string
          description: URI reference identifying the problem type
        title:
          type: string
          description: Short description of the issue.
        status:
          type: integer
          description: Http status code
        detail:
          type: string
          description: Explanation of the problem
        instance:
          type: string
          description: Resource path to the existing resource
        errors:
          type: array
          items:
            $ref: '#/components/schemas/ErrorsItems'
        link:
          $ref: '#/components/schemas/link'
      required:
        - type
        - title
        - status
        - detail
      title: '409'
    '500':
      type: object
      properties:
        type:
          type: string
          description: URI reference identifying the problem type
        title:
          type: string
          description: Short description of the issue.
        status:
          type: integer
          description: Http status code
        detail:
          type: string
          description: Explanation of the problem
        errors:
          type: array
          items:
            $ref: '#/components/schemas/ErrorsItems'
      required:
        - type
        - title
        - status
        - detail
      title: '500'
    EventSubscriptionStatus:
      type: string
      enum:
        - registered
        - suspended
        - failed
      description: >
        Status of the subscription. We return one of the following values:  

        - `registered` - You have set up the subscription, and we will notify
        you when an event occurs.  

        - `suspended` - We have deactivated the event subscription, and we won't
        notify you when an event occurs.  

        - `failed` - We couldn't contact your URI endpoint. We email the
        supportEmailAddress.  
      title: EventSubscriptionStatus
    notification:
      oneOf:
        - type: object
          properties:
            type:
              type: string
              enum:
                - webhook
              description: 'Discriminator value: webhook'
            uri:
              type: string
              description: Public endpoint that we send notifications to.
            secret:
              type: string
              description: >
                String that we send with a notification so that you can ensure
                it is a valid notification from our gateway. We include the
                value in the Payroc-Secret header parameter in the webhook
                call.  

                **Note:** In the response, we truncate the secret to the last 16
                characters and mask the first 10 characters.  
            supportEmailAddress:
              type: string
              description: >-
                Email address of the person or team that we contact if we can't
                deliver notifications.
          required:
            - type
            - uri
            - secret
            - supportEmailAddress
          description: webhook variant
      discriminator:
        propertyName: type
      title: notification
    EventSubscriptionMetadata:
      type: object
      properties: {}
      description: >-
        Object that you can send to include custom data in the request. For more
        information about how to use metadata, go to
        [Metadata](https://docs.payroc.com/api/metadata).
      title: EventSubscriptionMetadata
    eventSubscription:
      type: object
      properties:
        id:
          type: integer
          format: int64
          description: Unique identifier that we assigned to the event subscription.
        enabled:
          type: boolean
          description: >
            Indicates if we should notify you when the event occurs. The value
            is one of the following:  

            - `true` - We notify you when the event occurs.  

            - `false` - We don't notify you when the event occurs.  
        status:
          $ref: '#/components/schemas/EventSubscriptionStatus'
          description: >
            Status of the subscription. We return one of the following values:  

            - `registered` - You have set up the subscription, and we will
            notify you when an event occurs.  

            - `suspended` - We have deactivated the event subscription, and we
            won't notify you when an event occurs.  

            - `failed` - We couldn't contact your URI endpoint. We email the
            supportEmailAddress.  
        eventTypes:
          type: array
          items:
            type: string
          description: >-
            Array of events that you want to subscribe to. For a list of events,
            go to [Events
            List](https://docs.payroc.com/knowledge/events/events-list).
        notifications:
          type: array
          items:
            $ref: '#/components/schemas/notification'
          description: >-
            Array of polymorphic notification objects that contain information
            about how we contact you when an event occurs.
        metadata:
          $ref: '#/components/schemas/EventSubscriptionMetadata'
          description: >-
            Object that you can send to include custom data in the request. For
            more information about how to use metadata, go to
            [Metadata](https://docs.payroc.com/api/metadata).
      required:
        - enabled
        - eventTypes
        - notifications
      title: eventSubscription
    ErrorsItems:
      type: object
      properties:
        message:
          type: string
          description: Error message
      title: ErrorsItems
    link:
      type: object
      properties:
        rel:
          type: string
          description: >-
            Indicates the relationship between the current resource and the
            target resource.
        method:
          type: string
          description: HTTP method that you need to use with the target resource.
        href:
          type: string
          description: URL of the target resource.
      required:
        - rel
        - method
        - href
      description: Object that contains HATEOAS links for the resource.
      title: link
  securitySchemes:
    Bearer:
      type: http
      scheme: bearer

```

## Examples

### Event subscription created



**Request**

```json
undefined
```

**Response**

```json
{
  "enabled": true,
  "eventTypes": [
    "processingAccount.status.changed"
  ],
  "notifications": [
    {
      "type": "webhook",
      "secret": "**********oP3456",
      "supportEmailAddress": "jane.doe@example.com",
      "uri": "https://my-service/notification/endpoint"
    }
  ],
  "id": 2565435189324,
  "status": "registered",
  "metadata": {
    "yourCustomField": "abc123"
  }
}
```

**SDK Code**

```typescript Event subscription created
import { PayrocClient } from "payroc";

async function main() {
    const client = new PayrocClient();
    await client.notifications.eventSubscriptions.create({
        idempotencyKey: "8e03978e-40d5-43e8-bc93-6894a57f9324",
    });
}
main();

```

```python Event subscription created
from payroc import Payroc

client = Payroc()

client.notifications.event_subscriptions.create(
    idempotency_key="8e03978e-40d5-43e8-bc93-6894a57f9324",
)

```

```java Event subscription created
package com.example.usage;

import com.payroc.api.PayrocApiClient;
import com.payroc.api.resources.notifications.eventsubscriptions.requests.CreateEventSubscriptionsRequest;

public class Example {
    public static void main(String[] args) {
        PayrocApiClient client = PayrocApiClient
            .builder()
            .build();

        client.notifications().eventSubscriptions().create(
            CreateEventSubscriptionsRequest
                .builder()
                .idempotencyKey("8e03978e-40d5-43e8-bc93-6894a57f9324")
                .build()
        );
    }
}
```

```ruby Event subscription created
require "payroc"

client = Payroc::Client.new

client.notifications.event_subscriptions.create(idempotency_key: "8e03978e-40d5-43e8-bc93-6894a57f9324")

```

```csharp Event subscription created
using Payroc;
using System.Threading.Tasks;
using Payroc.Notifications.EventSubscriptions;

namespace Usage;

public class Example
{
    public async Task Do() {
        var client = new PayrocClient();

        await client.Notifications.EventSubscriptions.CreateAsync(
            new CreateEventSubscriptionsRequest {
                IdempotencyKey = "8e03978e-40d5-43e8-bc93-6894a57f9324",
                Body = new EventSubscription {
                    Enabled = false
                }
            }
        );
    }

}

```

```go Event subscription created
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://api.payroc.com/v1/event-subscriptions"

	req, _ := http.NewRequest("POST", url, nil)

	req.Header.Add("Idempotency-Key", "8e03978e-40d5-43e8-bc93-6894a57f9324")
	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```php Event subscription created
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.payroc.com/v1/event-subscriptions', [
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
    'Idempotency-Key' => '8e03978e-40d5-43e8-bc93-6894a57f9324',
  ],
]);

echo $response->getBody();
```

```swift Event subscription created
import Foundation

let headers = [
  "Idempotency-Key": "8e03978e-40d5-43e8-bc93-6894a57f9324",
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]

let request = NSMutableURLRequest(url: NSURL(string: "https://api.payroc.com/v1/event-subscriptions")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### Event subscription created metadata



**Request**

```json
undefined
```

**Response**

```json
{
  "enabled": true,
  "eventTypes": [
    "processingAccount.status.changed"
  ],
  "notifications": [
    {
      "type": "webhook",
      "secret": "**********oP3456",
      "supportEmailAddress": "jane.doe@example.com",
      "uri": "https://my-server/notification/endpoint"
    }
  ],
  "id": 2565435189324,
  "status": "registered",
  "metadata": {
    "responsiblePerson": "Jane Doe"
  }
}
```

**SDK Code**

```typescript Event subscription created metadata
import { PayrocClient } from "payroc";

async function main() {
    const client = new PayrocClient();
    await client.notifications.eventSubscriptions.create({
        idempotencyKey: "8e03978e-40d5-43e8-bc93-6894a57f9324",
    });
}
main();

```

```python Event subscription created metadata
from payroc import Payroc

client = Payroc()

client.notifications.event_subscriptions.create(
    idempotency_key="8e03978e-40d5-43e8-bc93-6894a57f9324",
)

```

```java Event subscription created metadata
package com.example.usage;

import com.payroc.api.PayrocApiClient;
import com.payroc.api.resources.notifications.eventsubscriptions.requests.CreateEventSubscriptionsRequest;

public class Example {
    public static void main(String[] args) {
        PayrocApiClient client = PayrocApiClient
            .builder()
            .build();

        client.notifications().eventSubscriptions().create(
            CreateEventSubscriptionsRequest
                .builder()
                .idempotencyKey("8e03978e-40d5-43e8-bc93-6894a57f9324")
                .build()
        );
    }
}
```

```ruby Event subscription created metadata
require "payroc"

client = Payroc::Client.new

client.notifications.event_subscriptions.create(idempotency_key: "8e03978e-40d5-43e8-bc93-6894a57f9324")

```

```csharp Event subscription created metadata
using Payroc;
using System.Threading.Tasks;
using Payroc.Notifications.EventSubscriptions;

namespace Usage;

public class Example
{
    public async Task Do() {
        var client = new PayrocClient();

        await client.Notifications.EventSubscriptions.CreateAsync(
            new CreateEventSubscriptionsRequest {
                IdempotencyKey = "8e03978e-40d5-43e8-bc93-6894a57f9324",
                Body = new EventSubscription {
                    Enabled = false
                }
            }
        );
    }

}

```

```go Event subscription created metadata
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://api.payroc.com/v1/event-subscriptions"

	req, _ := http.NewRequest("POST", url, nil)

	req.Header.Add("Idempotency-Key", "8e03978e-40d5-43e8-bc93-6894a57f9324")
	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```php Event subscription created metadata
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.payroc.com/v1/event-subscriptions', [
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
    'Idempotency-Key' => '8e03978e-40d5-43e8-bc93-6894a57f9324',
  ],
]);

echo $response->getBody();
```

```swift Event subscription created metadata
import Foundation

let headers = [
  "Idempotency-Key": "8e03978e-40d5-43e8-bc93-6894a57f9324",
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]

let request = NSMutableURLRequest(url: NSURL(string: "https://api.payroc.com/v1/event-subscriptions")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### Create event subscription



**Request**

```json
{
  "enabled": true,
  "eventTypes": [
    "processingAccount.status.changed"
  ],
  "notifications": [
    {
      "type": "webhook",
      "secret": "aBcD1234eFgH5678iJkL9012mNoP3456",
      "supportEmailAddress": "jane.doe@example.com",
      "uri": "https://my-server/notification/endpoint"
    }
  ],
  "metadata": {
    "yourCustomField": "abc123"
  }
}
```

**Response**

```json
{
  "enabled": true,
  "eventTypes": [
    "processingAccount.status.changed"
  ],
  "notifications": [
    {
      "type": "webhook",
      "secret": "**********oP3456",
      "supportEmailAddress": "jane.doe@example.com",
      "uri": "https://my-service/notification/endpoint"
    }
  ],
  "id": 2565435189324,
  "status": "registered",
  "metadata": {
    "yourCustomField": "abc123"
  }
}
```

**SDK Code**

```typescript Create event subscription
import { PayrocClient } from "payroc";

async function main() {
    const client = new PayrocClient();
    await client.notifications.eventSubscriptions.create({
        idempotencyKey: "8e03978e-40d5-43e8-bc93-6894a57f9324",
        body: {
            enabled: true,
            eventTypes: [
                "processingAccount.status.changed",
            ],
            notifications: [
                {
                    type: "webhook",
                    secret: "aBcD1234eFgH5678iJkL9012mNoP3456",
                    supportEmailAddress: "jane.doe@example.com",
                    uri: "https://my-server/notification/endpoint",
                },
            ],
            metadata: {
                "yourCustomField": "abc123",
            },
        },
    });
}
main();

```

```python Create event subscription
from payroc import Payroc, Notification_Webhook

client = Payroc()

client.notifications.event_subscriptions.create(
    idempotency_key="8e03978e-40d5-43e8-bc93-6894a57f9324",
    enabled=True,
    event_types=[
        "processingAccount.status.changed"
    ],
    notifications=[
        Notification_Webhook(
            secret="aBcD1234eFgH5678iJkL9012mNoP3456",
            support_email_address="jane.doe@example.com",
            uri="https://my-server/notification/endpoint",
        )
    ],
    metadata={
        "yourCustomField": "abc123"
    },
)

```

```java Create event subscription
package com.example.usage;

import com.payroc.api.PayrocApiClient;
import com.payroc.api.resources.notifications.eventsubscriptions.requests.CreateEventSubscriptionsRequest;
import com.payroc.api.types.EventSubscription;
import com.payroc.api.types.Notification;
import com.payroc.api.types.Webhook;
import java.util.Arrays;
import java.util.HashMap;

public class Example {
    public static void main(String[] args) {
        PayrocApiClient client = PayrocApiClient
            .builder()
            .build();

        client.notifications().eventSubscriptions().create(
            CreateEventSubscriptionsRequest
                .builder()
                .idempotencyKey("8e03978e-40d5-43e8-bc93-6894a57f9324")
                .body(
                    EventSubscription
                        .builder()
                        .enabled(true)
                        .eventTypes(
                            Arrays.asList("processingAccount.status.changed")
                        )
                        .notifications(
                            Arrays.asList(
                                Notification.webhook(
                                    Webhook
                                        .builder()
                                        .uri("https://my-server/notification/endpoint")
                                        .secret("aBcD1234eFgH5678iJkL9012mNoP3456")
                                        .supportEmailAddress("jane.doe@example.com")
                                        .build()
                                )
                            )
                        )
                        .metadata(
                            new HashMap<String, Object>() {{
                                put("yourCustomField", "abc123");
                            }}
                        )
                        .build()
                )
                .build()
        );
    }
}
```

```ruby Create event subscription
require "payroc"

client = Payroc::Client.new

client.notifications.event_subscriptions.create(
  idempotency_key: "8e03978e-40d5-43e8-bc93-6894a57f9324",
  enabled: true,
  event_types: ["processingAccount.status.changed"],
  notifications: [],
  metadata: {}
)

```

```csharp Create event subscription
using Payroc;
using System.Threading.Tasks;
using Payroc.Notifications.EventSubscriptions;
using System.Collections.Generic;

namespace Usage;

public class Example
{
    public async Task Do() {
        var client = new PayrocClient();

        await client.Notifications.EventSubscriptions.CreateAsync(
            new CreateEventSubscriptionsRequest {
                IdempotencyKey = "8e03978e-40d5-43e8-bc93-6894a57f9324",
                Body = new EventSubscription {
                    Enabled = true,
                    EventTypes = new List<string>(){
                        "processingAccount.status.changed",
                    }
                    ,
                    Notifications = new List<Notification>(){
                        new Notification(
                            new Webhook {
                                Secret = "aBcD1234eFgH5678iJkL9012mNoP3456",
                                SupportEmailAddress = "jane.doe@example.com",
                                Uri = "https://my-server/notification/endpoint"
                            }
                        ),
                    }
                    ,
                    Metadata = new Dictionary<string, object?>(){
                        ["yourCustomField"] = "abc123",
                    }

                }
            }
        );
    }

}

```

```go Create event subscription
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.payroc.com/v1/event-subscriptions"

	payload := strings.NewReader("{\n  \"enabled\": true,\n  \"eventTypes\": [\n    \"processingAccount.status.changed\"\n  ],\n  \"notifications\": [\n    {\n      \"type\": \"webhook\",\n      \"secret\": \"aBcD1234eFgH5678iJkL9012mNoP3456\",\n      \"supportEmailAddress\": \"jane.doe@example.com\",\n      \"uri\": \"https://my-server/notification/endpoint\"\n    }\n  ],\n  \"metadata\": {\n    \"yourCustomField\": \"abc123\"\n  }\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Idempotency-Key", "8e03978e-40d5-43e8-bc93-6894a57f9324")
	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```php Create event subscription
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.payroc.com/v1/event-subscriptions', [
  'body' => '{
  "enabled": true,
  "eventTypes": [
    "processingAccount.status.changed"
  ],
  "notifications": [
    {
      "type": "webhook",
      "secret": "aBcD1234eFgH5678iJkL9012mNoP3456",
      "supportEmailAddress": "jane.doe@example.com",
      "uri": "https://my-server/notification/endpoint"
    }
  ],
  "metadata": {
    "yourCustomField": "abc123"
  }
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
    'Idempotency-Key' => '8e03978e-40d5-43e8-bc93-6894a57f9324',
  ],
]);

echo $response->getBody();
```

```swift Create event subscription
import Foundation

let headers = [
  "Idempotency-Key": "8e03978e-40d5-43e8-bc93-6894a57f9324",
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "enabled": true,
  "eventTypes": ["processingAccount.status.changed"],
  "notifications": [
    [
      "type": "webhook",
      "secret": "aBcD1234eFgH5678iJkL9012mNoP3456",
      "supportEmailAddress": "jane.doe@example.com",
      "uri": "https://my-server/notification/endpoint"
    ]
  ],
  "metadata": ["yourCustomField": "abc123"]
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.payroc.com/v1/event-subscriptions")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### Create event subscription with metadata



**Request**

```json
{
  "enabled": true,
  "eventTypes": [
    "processingAccount.status.changed"
  ],
  "notifications": [
    {
      "type": "webhook",
      "secret": "aBcD1234eFgH5678iJkL9012mNoP3456",
      "supportEmailAddress": "jane.doe@example.com",
      "uri": "https://my-server/notification/endpoint"
    }
  ],
  "metadata": {
    "responsiblePerson": "Jane Doe"
  }
}
```

**Response**

```json
{
  "enabled": true,
  "eventTypes": [
    "processingAccount.status.changed"
  ],
  "notifications": [
    {
      "type": "webhook",
      "secret": "**********oP3456",
      "supportEmailAddress": "jane.doe@example.com",
      "uri": "https://my-service/notification/endpoint"
    }
  ],
  "id": 2565435189324,
  "status": "registered",
  "metadata": {
    "yourCustomField": "abc123"
  }
}
```

**SDK Code**

```typescript Create event subscription with metadata
import { PayrocClient } from "payroc";

async function main() {
    const client = new PayrocClient();
    await client.notifications.eventSubscriptions.create({
        idempotencyKey: "8e03978e-40d5-43e8-bc93-6894a57f9324",
        body: {
            enabled: true,
            eventTypes: [
                "processingAccount.status.changed",
            ],
            notifications: [
                {
                    type: "webhook",
                    secret: "aBcD1234eFgH5678iJkL9012mNoP3456",
                    supportEmailAddress: "jane.doe@example.com",
                    uri: "https://my-server/notification/endpoint",
                },
            ],
            metadata: {
                "responsiblePerson": "Jane Doe",
            },
        },
    });
}
main();

```

```python Create event subscription with metadata
from payroc import Payroc, Notification_Webhook

client = Payroc()

client.notifications.event_subscriptions.create(
    idempotency_key="8e03978e-40d5-43e8-bc93-6894a57f9324",
    enabled=True,
    event_types=[
        "processingAccount.status.changed"
    ],
    notifications=[
        Notification_Webhook(
            secret="aBcD1234eFgH5678iJkL9012mNoP3456",
            support_email_address="jane.doe@example.com",
            uri="https://my-server/notification/endpoint",
        )
    ],
    metadata={
        "responsiblePerson": "Jane Doe"
    },
)

```

```java Create event subscription with metadata
package com.example.usage;

import com.payroc.api.PayrocApiClient;
import com.payroc.api.resources.notifications.eventsubscriptions.requests.CreateEventSubscriptionsRequest;
import com.payroc.api.types.EventSubscription;
import com.payroc.api.types.Notification;
import com.payroc.api.types.Webhook;
import java.util.Arrays;
import java.util.HashMap;

public class Example {
    public static void main(String[] args) {
        PayrocApiClient client = PayrocApiClient
            .builder()
            .build();

        client.notifications().eventSubscriptions().create(
            CreateEventSubscriptionsRequest
                .builder()
                .idempotencyKey("8e03978e-40d5-43e8-bc93-6894a57f9324")
                .body(
                    EventSubscription
                        .builder()
                        .enabled(true)
                        .eventTypes(
                            Arrays.asList("processingAccount.status.changed")
                        )
                        .notifications(
                            Arrays.asList(
                                Notification.webhook(
                                    Webhook
                                        .builder()
                                        .uri("https://my-server/notification/endpoint")
                                        .secret("aBcD1234eFgH5678iJkL9012mNoP3456")
                                        .supportEmailAddress("jane.doe@example.com")
                                        .build()
                                )
                            )
                        )
                        .metadata(
                            new HashMap<String, Object>() {{
                                put("responsiblePerson", "Jane Doe");
                            }}
                        )
                        .build()
                )
                .build()
        );
    }
}
```

```ruby Create event subscription with metadata
require "payroc"

client = Payroc::Client.new

client.notifications.event_subscriptions.create(
  idempotency_key: "8e03978e-40d5-43e8-bc93-6894a57f9324",
  enabled: true,
  event_types: ["processingAccount.status.changed"],
  notifications: [],
  metadata: {}
)

```

```csharp Create event subscription with metadata
using Payroc;
using System.Threading.Tasks;
using Payroc.Notifications.EventSubscriptions;
using System.Collections.Generic;

namespace Usage;

public class Example
{
    public async Task Do() {
        var client = new PayrocClient();

        await client.Notifications.EventSubscriptions.CreateAsync(
            new CreateEventSubscriptionsRequest {
                IdempotencyKey = "8e03978e-40d5-43e8-bc93-6894a57f9324",
                Body = new EventSubscription {
                    Enabled = true,
                    EventTypes = new List<string>(){
                        "processingAccount.status.changed",
                    }
                    ,
                    Notifications = new List<Notification>(){
                        new Notification(
                            new Webhook {
                                Secret = "aBcD1234eFgH5678iJkL9012mNoP3456",
                                SupportEmailAddress = "jane.doe@example.com",
                                Uri = "https://my-server/notification/endpoint"
                            }
                        ),
                    }
                    ,
                    Metadata = new Dictionary<string, object?>(){
                        ["responsiblePerson"] = "Jane Doe",
                    }

                }
            }
        );
    }

}

```

```go Create event subscription with metadata
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.payroc.com/v1/event-subscriptions"

	payload := strings.NewReader("{\n  \"enabled\": true,\n  \"eventTypes\": [\n    \"processingAccount.status.changed\"\n  ],\n  \"notifications\": [\n    {\n      \"type\": \"webhook\",\n      \"secret\": \"aBcD1234eFgH5678iJkL9012mNoP3456\",\n      \"supportEmailAddress\": \"jane.doe@example.com\",\n      \"uri\": \"https://my-server/notification/endpoint\"\n    }\n  ],\n  \"metadata\": {\n    \"responsiblePerson\": \"Jane Doe\"\n  }\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Idempotency-Key", "8e03978e-40d5-43e8-bc93-6894a57f9324")
	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```php Create event subscription with metadata
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.payroc.com/v1/event-subscriptions', [
  'body' => '{
  "enabled": true,
  "eventTypes": [
    "processingAccount.status.changed"
  ],
  "notifications": [
    {
      "type": "webhook",
      "secret": "aBcD1234eFgH5678iJkL9012mNoP3456",
      "supportEmailAddress": "jane.doe@example.com",
      "uri": "https://my-server/notification/endpoint"
    }
  ],
  "metadata": {
    "responsiblePerson": "Jane Doe"
  }
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
    'Idempotency-Key' => '8e03978e-40d5-43e8-bc93-6894a57f9324',
  ],
]);

echo $response->getBody();
```

```swift Create event subscription with metadata
import Foundation

let headers = [
  "Idempotency-Key": "8e03978e-40d5-43e8-bc93-6894a57f9324",
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "enabled": true,
  "eventTypes": ["processingAccount.status.changed"],
  "notifications": [
    [
      "type": "webhook",
      "secret": "aBcD1234eFgH5678iJkL9012mNoP3456",
      "supportEmailAddress": "jane.doe@example.com",
      "uri": "https://my-server/notification/endpoint"
    ]
  ],
  "metadata": ["responsiblePerson": "Jane Doe"]
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.payroc.com/v1/event-subscriptions")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```