# Create Webhook

> POST /webhooks — create a webhook to receive real-time notifications about email events.

`POST /webhooks`

Creates a webhook. SendPing POSTs an event payload to your `endpoint` URL whenever one of the subscribed `events` occurs. The response includes a `signing_secret` — store it and use it to verify the signature on every incoming request. See [Webhooks](https://www.sendping.co/docs/webhooks/overview).

**Body parameters**

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `endpoint` | string | Yes | The HTTPS URL where webhook events will be sent. |
| `events` | string[] | Yes | Array of event types to subscribe to. See the table below. |
| `secret` | string | No | Optional. Provide your own signing secret (e.g. to mirror a secret across providers). When omitted, SendPing mints a fresh `whsec_…` secret. Either way the plaintext is returned once in this response and never again. |

**Event types**

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `email.sent` | enum | No | SendPing accepted the email and queued it for delivery. |
| `email.delivered` | enum | No | The receiving server accepted the message. |
| `email.delivery_delayed` | enum | No | Delivery was temporarily deferred and SendPing is retrying. |
| `email.bounced` | enum | No | The message could not be delivered (hard rejection). |
| `email.complained` | enum | No | The recipient marked the message as spam. |
| `email.opened` | enum | No | The recipient’s mail client loaded the tracking pixel (requires open tracking). |
| `email.clicked` | enum | No | The recipient clicked a tracked link (requires click tracking). |
| `email.failed` | enum | No | The email could not be sent (e.g. invalid recipient, quota reached). |
| `email.scheduled` | enum | No | The email was accepted for future delivery with a `scheduled_at` time. |
| `email.suppressed` | enum | No | The send was skipped because the recipient is on the account suppression list. |
| `email.received` | enum | No | An inbound email arrived at one of your verified receiving domains. |
| `email.replied` | enum | No | A reply to one of your sent emails was detected. |
| `email.unsubscribed` | enum | No | A recipient unsubscribed via an unsubscribe link or header. |
| `contact.created` | enum | No | A contact was created in one of your audiences. |
| `contact.updated` | enum | No | A contact was updated. |
| `contact.deleted` | enum | No | A contact was deleted. |
| `domain.created` | enum | No | A domain was added to your account. |
| `domain.updated` | enum | No | A domain’s settings or verification status changed. |
| `domain.deleted` | enum | No | A domain was removed from your account. |

**Node.js**

```js
import { SendPing } from 'sendping';

const mb = new SendPing('mb_xxxxxxxxx');

const { data, error } = await mb.webhooks.create({
  "endpoint": "https://example.com/handler",
  "events": ["email.sent", "email.delivered"]
});
console.log({ data, error });
```

**Ruby**

```ruby
require "sendping"

SendPing.api_key = "mb_xxxxxxxxx"

SendPing::Webhooks.create({
  "endpoint": "https://example.com/handler",
  "events": [
    "email.sent",
    "email.delivered"
  ]
})
```

**PHP**

```php
<?php
require 'vendor/autoload.php';

use SendPing\SendPing;

$sendping = SendPing::client('mb_xxxxxxxxx');

$sendping->webhooks->create([
  'endpoint' => "https://example.com/handler",
  'events' => [
    "email.sent",
    "email.delivered"
  ]
]);
```

**Python**

```python
import sendping

sendping.api_key = "mb_xxxxxxxxx"

sendping.Webhooks.create({
  "endpoint": "https://example.com/handler",
  "events": [
    "email.sent",
    "email.delivered"
  ]
})
```

**Go**

```go
import "github.com/shekhu10/sendping-sdks/sendping-go"

client := sendping.NewClient("mb_xxxxxxxxx")

webhook, err := client.Webhooks.Create(&sendping.CreateWebhookRequest{
    Endpoint: "https://example.com/handler",
    Events:   []string{"email.sent", "email.delivered"},
})
```

**Rust**

```rust
use sendping::{CreateWebhookOptions, SendPing};

let mb = SendPing::new("mb_xxxxxxxxx");

let params = CreateWebhookOptions::new(
    "https://example.com/handler",
    ["email.sent", "email.delivered"],
);
let _webhook = mb.webhooks.create(params).await?;
```

**Java**

```java
import co.sendping.SendPing;
import co.sendping.SendPingResponse;
import co.sendping.requests.CreateWebhookRequest;

SendPing sendping = new SendPing("mb_xxxxxxxxx");

CreateWebhookRequest request = CreateWebhookRequest.builder()
        .endpoint("https://example.com/handler")
        .events("email.sent", "email.delivered")
        .build();

SendPingResponse response = sendping.webhooks().create(request);
```

**.NET**

```csharp
using SendPing;

ISendPing sendping = SendPingClient.Create("mb_xxxxxxxxx");

var resp = await sendping.WebhookCreateAsync(new WebhookCreateOptions
{
    Endpoint = "https://example.com/handler",
    Events = new List<string> { "email.sent", "email.delivered" },
});
```

**cURL**

```bash
curl -X POST 'https://www.sendping.co/api/webhooks' \
  -H 'Authorization: Bearer mb_xxxxxxxxx' \
  -H 'Content-Type: application/json' \
  -d '{
  "endpoint": "https://example.com/handler",
  "events": ["email.sent", "email.delivered"]
}'
```

**CLI**

```bash
sendping webhooks create \
  --endpoint 'https://example.com/handler' \
  --events 'email.sent,email.delivered'
```

### Response

```json
{
  "object": "webhook",
  "id": "17",
  "signing_secret": "whsec_xxxxxxxxxx"
}
```

> **Warning:** The `signing_secret` is only returned here, at creation. Store it securely — it cannot be retrieved again later.
