> This page is for MVS Pay.

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

# Create a webhook endpoint

POST https://pay.mvscloud.com/api/webhooks
Content-Type: application/json

Registers a new outbound webhook endpoint for the organization. The `url` must be a valid HTTPS URL and at least one event type is required. A signing `secret` (prefixed `whsec_`) is generated and returned **only** in this response — store it to verify delivery signatures, as it cannot be retrieved later.

Reference: https://docs.mvscloud.com/mvs-pay/api/webhooks/create-webhook

## Authentication

- `x-api-key` header (required) — A scoped MvsPayApiKey, e.g. `mvspay_live_…`. Mint and scope keys from the dashboard (Settings → API Keys).

## Request

### Body (application/json)

This endpoint expects a WebhookCreateRequest.

- `url` (string, required) — Destination URL; must use the https scheme.
- `events` (list of string, required) — Event types to subscribe to. At least one is required.
- `description` (string, optional, nullable) — Optional human-readable label.

## Response

### 201

The created webhook endpoint, including the one-time signing secret.

- `id` (string, required)
- `url` (string, required)
- `events` (list of string, required)
- `secret` (string, required) — Signing secret (prefixed `whsec_`) used to verify delivery signatures. Returned only at creation.
- `isActive` (boolean, required)
- `created_at` (datetime, required)
- `description` (string, optional, nullable)

## Errors

### 400 Bad Request Error

Invalid request (e.g. malformed JSON, missing required field, amount below minimum).

- `error` (ErrorResponseError, required)

### 401 Unauthorized Error

Missing or invalid API key.

- `error` (ErrorResponseError, required)

### 403 Forbidden Error

The key lacks the required scope, or the body references a different organization.

- `error` (ErrorResponseError, required)

### 500 Internal Server Error

Unexpected server error.

- `error` (ErrorResponseError, required)

## Types

### ErrorResponseError

- `code` (string, required) — e.g. UNAUTHORIZED, FORBIDDEN, ERROR.
- `message` (string, required)
- `details` (map from string to any, optional)

## Examples

**Request**

```json
{
  "url": "https://example.com/webhooks/mvs-pay",
  "events": [
    "payment.succeeded",
    "payment.failed"
  ],
  "description": "Production billing listener"
}
```

**Response**

```json
{
  "id": "whk_01HZX2sample",
  "url": "https://example.com/webhooks/mvs-pay",
  "events": [
    "payment.succeeded",
    "payment.failed"
  ],
  "secret": "whsec_3f9c1a2b4d5e6f708192a3b4c5d6e7f8",
  "isActive": true,
  "created_at": "2026-06-21T12:00:00.000Z",
  "description": "Production billing listener"
}
```

**SDK Code**

```python Webhooks_createWebhook_example
import requests

url = "https://pay.mvscloud.com/api/webhooks"

payload = {
    "url": "https://example.com/webhooks/mvs-pay",
    "events": ["payment.succeeded", "payment.failed"],
    "description": "Production billing listener"
}
headers = {
    "x-api-key": "<apiKey>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript Webhooks_createWebhook_example
const url = 'https://pay.mvscloud.com/api/webhooks';
const options = {
  method: 'POST',
  headers: {'x-api-key': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"url":"https://example.com/webhooks/mvs-pay","events":["payment.succeeded","payment.failed"],"description":"Production billing listener"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Webhooks_createWebhook_example
package main

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

func main() {

	url := "https://pay.mvscloud.com/api/webhooks"

	payload := strings.NewReader("{\n  \"url\": \"https://example.com/webhooks/mvs-pay\",\n  \"events\": [\n    \"payment.succeeded\",\n    \"payment.failed\"\n  ],\n  \"description\": \"Production billing listener\"\n}")

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

	req.Header.Add("x-api-key", "<apiKey>")
	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))

}
```

```ruby Webhooks_createWebhook_example
require 'uri'
require 'net/http'

url = URI("https://pay.mvscloud.com/api/webhooks")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["x-api-key"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"url\": \"https://example.com/webhooks/mvs-pay\",\n  \"events\": [\n    \"payment.succeeded\",\n    \"payment.failed\"\n  ],\n  \"description\": \"Production billing listener\"\n}"

response = http.request(request)
puts response.read_body
```

```java Webhooks_createWebhook_example
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://pay.mvscloud.com/api/webhooks")
  .header("x-api-key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"url\": \"https://example.com/webhooks/mvs-pay\",\n  \"events\": [\n    \"payment.succeeded\",\n    \"payment.failed\"\n  ],\n  \"description\": \"Production billing listener\"\n}")
  .asString();
```

```php Webhooks_createWebhook_example
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://pay.mvscloud.com/api/webhooks', [
  'body' => '{
  "url": "https://example.com/webhooks/mvs-pay",
  "events": [
    "payment.succeeded",
    "payment.failed"
  ],
  "description": "Production billing listener"
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'x-api-key' => '<apiKey>',
  ],
]);

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

```csharp Webhooks_createWebhook_example
using RestSharp;

var client = new RestClient("https://pay.mvscloud.com/api/webhooks");
var request = new RestRequest(Method.POST);
request.AddHeader("x-api-key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"url\": \"https://example.com/webhooks/mvs-pay\",\n  \"events\": [\n    \"payment.succeeded\",\n    \"payment.failed\"\n  ],\n  \"description\": \"Production billing listener\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Webhooks_createWebhook_example
import Foundation

let headers = [
  "x-api-key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "url": "https://example.com/webhooks/mvs-pay",
  "events": ["payment.succeeded", "payment.failed"],
  "description": "Production billing listener"
] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://pay.mvscloud.com/api/webhooks")! 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()
```