> ## Documentation Index
> Fetch the complete documentation index at: https://razorpay-60c89f9a-mintlify-audit-missing-sections-1778528421.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Create a Webhook

> **POST** `/v2/accounts/:account_id/webhooks`

Use this API endpoint to create a webhook. Know about the [various error responses](/api/partners/errors) for this API.

<Info>
  **Handy Tips**
</Info>

You can create up to 30 webhooks for an `account_id`.

### Request

````cURL: Curl theme={null}
curl -X POST https://api.razorpay.com/v2/accounts/acc_JOGUdtKu3dB03d/webhooks \
-u  \
-H "Content-Type: application/json" \
-d '{
  "url": "https://google.com",
  "alert_email": "gaurav.kumar@example.com",
  "secret": "12345",
  "events": [
    "payment.authorized",
    "payment.failed",
    "payment.captured",
    "payment.dispute.created",
    "refund.failed",
    "refund.created"
  ]
}'

```java: Java

RazorpayClient razorpay = new RazorpayClient("[ACCESS_TOKEN]");

String accountId = "acc_GP4lfNA0iIMn5B";

JSONObject webhookRequest = new JSONObject();
webhookRequest.put("url","https://google.com");
webhookRequest.put("alert_email","gaurav.kumar@example.com");
webhookRequest.put("secret","12345");

ArrayList events = new ArrayList();
events.add("payment.authorized");
events.add("payment.failed");
events.add("payment.captured");
events.add("payment.dispute.created");
events.add("refund.failed");
events.add("refund.created");

webhookRequest.put("events",events);

Webhook webhook = instance.webhook.create(accountId, webhookRequest);

```ruby: Ruby
require "razorpay"
Razorpay.setup('ACCESS_TOKEN')
accountId = "acc_GP4lfNA0iIMn5B"

Razorpay::Webhook.create({
  "url": "https://google.com",
  "alert_email": "gaurav.kumar@example.com",
  "secret": "12345",
  "events": [
    "payment.authorized",
    "payment.failed",
    "payment.captured",
    "payment.dispute.created",
    "refund.failed",
    "refund.created"
  ]
}, accountId)

```csharp: .NET
RazorpayClient client = new RazorpayClient("[ACCESS_TOKEN]");

String accountId = "acc_ua2tBezhcEBvap";

Dictionary webhookRequest = new Dictionary();
webhookRequest.Add("url", "https://www.google.com");
webhookRequest.Add("alert_email", "gaurav.kumar@example.com");
List events = new List();
events.Add("refund.created");
events.Add("payment.authorized");
events.Add("payment.failed");
events.Add("payment.captured");
events.Add("payment.dispute.created");
events.Add("refund.failed");
events.Add("refund.created");
webhookRequest.Add("secret", "12345");
webhookRequest.Add("events", events);

Webhook webhook = client.Webhook.Create(webhookRequest, accountId);
````

### Response

```json: Success theme={null}
{
  "id": "JebiXkKGYwua5L",
  "created_at": 1654605478,
  "updated_at": 1654605478,
  "service": "beta-api-live",
  "owner_id": "JOGUdtKu3dB03d",
  "owner_type": "merchant",
  "context": [],
  "disabled_at": 0,
  "url": "https://google.com",
  "alert_email": "gaurav.kumar@example.com",
  "secret_exists": true,
  "entity": "webhook",
  "active": true,
  "events": [
    "payment.authorized",
    "payment.failed",
    "payment.captured",
    "payment.dispute.created",
    "refund.failed",
    "refund.created"
  ]
}
```

### Parameters

`account_id` *mandatory*
: `string` The unique identifier of the sub-merchant account generated by Razorpay for which a webhook is created. For example, `acc_H3kYHQ635sBwXG`. This id is used to fetch, update and delete a webhook. The webhook is created for this sub-merchant account id.

### Parameters

`url` *mandatory*
: `string` The URL where you receive the webhook payload when an event is triggered. The maximum length is 255 characters.

`alert_email` *optional*
: `string`  This is the email address to which notifications must be sent in case of webhook failure.

`secret` *optional*
: `string` A secret for the webhook endpoint that is used to validate that the webhook is from Razorpay.

`events` *mandatory*
: `object` The required events from the list of Active Events. For example, `payment.authorized`, `payment.captured`, `payment.failed`, `payment.dispute.created`, `refund.failed`, `refund.created` and so on.

### Parameters

`id`
: `string` The unique identifier of the webhook generated by Razorpay. For example, `HK890egfiItP3H`.

`created_at`
: `integer` The Unix timestamp at which the webhook has been created.

`updated_at`
: `integer` The Unix timestamp at which the webhook has been updated.

`owner_id`
: `string` The unique identifier generated by Razorpay for the sub-merchant who will receive the webhooks. For example, in this case, it will be `account_id` passed in the API URL.

`owner_type`
: `string` Indicates the type of owner. For example, in this case, it will be the merchant.

`url`
: `string` The URL where you receive the webhook payload when an event is triggered. The maximum length is 255 characters.

`secret`
: `string` A secret for the webhook endpoint used to validate that the webhook is from Razorpay.

`alert_email`
: `string`  This is the email address to which notifications must be sent in case of webhook failure.

`secret_exists`
: `boolean` This attribute will be set to `true` if a secret password has been set for the webhook endpoint.

`entity`
: `string` Indicates the type of entity. For example, in this case, it will be **webhook**.

`active`
: `string`  Indicates the status of webhook.

* `true`: Webhook in an activated state.
* `false`: Webhook in a deactivated state.

`events`
: `object` The required events from the list of Active Events. For example, `payment.authorized`, `payment.captured`, `payment.failed`, `payment.dispute.created`, `refund.failed`, `refund.created` and so on.
