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

# Set Webhook URL

POST https://api.vtuagent.com/v1/webhook/set
Content-Type: application/json

Registers the HTTPS endpoint that receives transaction notifications. One URL per account; calling again replaces it.

#### Delivery

We `POST` a JSON body to your URL with a 10-second timeout. There are **no retries** and **no `Authorization` header** — verify the `hash` field instead: `hash = hex( SHA-256( "<your_api_key>:<reference>" ) )`. Compare with constant-time equality and respond `200` promptly.

The body always has exactly eight keys — `event`, `reference`, `status`, `amount`, `product_type`, `details`, `hash`, `timestamp` — see the `WebhookPayload` schema for the exact body.

| `event`                    | Sent by                  | When                                                                       |
| -------------------------- | ------------------------ | -------------------------------------------------------------------------- |
| `airtime.purchase.success` | `/v1/airtime/purchase`   | Provider confirmed delivery                                                |
| `airtime.purchase.failed`  | `/v1/airtime/purchase`   | Provider rejected or was unreachable — wallet refunded                     |
| `airtime.purchase.pending` | `/v1/airtime/purchase`   | Provider still processing                                                  |
| `data.purchase.success`    | `/v1/data/purchase`      | Provider confirmed delivery                                                |
| `data.purchase.failed`     | `/v1/data/purchase`      | Provider rejected — wallet refunded                                        |
| `transaction.requery`      | `/v1/transaction/status` | Every call to the status endpoint; `status` mirrors the stored transaction |

Cable TV and electricity purchases do not emit webhooks — rely on the synchronous response or `/v1/transaction/status`.

Reference: https://docs.vtuagent.com/api-reference/vtu-agent-consumable-api/webhooks/set-webhook-url

## Authentication

- `Authorization` header (bearer token, required) — API key issued from the VTUAgent dashboard, sent as `Authorization: Bearer {your_api_key}`.

## Request

### Body (application/json)

This endpoint expects a WebhookSetRequest.

- `webhook_url` (string, required) — Absolute URL.

## Response

### 200

Webhook URL saved

- `status` (enum, optional)
  - Allowed values: `success`
- `message` (string, optional)
- `data` (WebhookSetResponseData, optional)

## Errors

### 400 Bad Request Error

Malformed body or invalid URL

- `status` (enum, required)
  - Allowed values: `error`
- `message` (string, required)
- `error` (string, optional) — Validator detail, present only on validation failures.

### 401 Unauthorized Error

Missing, invalid or revoked API key. Note: this envelope has no `status` field.

- `message` (string, required)
- `error` (string, required)

### 403 Forbidden Error

Account has no active API key

- `status` (enum, required)
  - Allowed values: `error`
- `message` (string, required)
- `error` (string, optional) — Validator detail, present only on validation failures.

### 500 Internal Server Error

Internal error

- `status` (enum, required)
  - Allowed values: `error`
- `message` (string, required)
- `error` (string, optional) — Validator detail, present only on validation failures.

## Types

### WebhookSetResponseData

- `webhook_url` (string, optional)

## Examples

**Request**

```json
{
  "webhook_url": "https://example.com/vtuagent/webhook"
}
```

**Response**

```json
{
  "status": "success",
  "message": "Webhook URL updated successfully",
  "data": {
    "webhook_url": "https://example.com/vtuagent/webhook"
  }
}
```

**SDK Code**

```python
import requests

url = "https://api.vtuagent.com/v1/webhook/set"

payload = { "webhook_url": "https://example.com/vtuagent/webhook" }
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript
const url = 'https://api.vtuagent.com/v1/webhook/set';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"webhook_url":"https://example.com/vtuagent/webhook"}'
};

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

```go
package main

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

func main() {

	url := "https://api.vtuagent.com/v1/webhook/set"

	payload := strings.NewReader("{\n  \"webhook_url\": \"https://example.com/vtuagent/webhook\"\n}")

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

	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))

}
```

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

url = URI("https://api.vtuagent.com/v1/webhook/set")

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

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"webhook_url\": \"https://example.com/vtuagent/webhook\"\n}"

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

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

HttpResponse<String> response = Unirest.post("https://api.vtuagent.com/v1/webhook/set")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"webhook_url\": \"https://example.com/vtuagent/webhook\"\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.vtuagent.com/v1/webhook/set', [
  'body' => '{
  "webhook_url": "https://example.com/vtuagent/webhook"
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://api.vtuagent.com/v1/webhook/set");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"webhook_url\": \"https://example.com/vtuagent/webhook\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = ["webhook_url": "https://example.com/vtuagent/webhook"] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://api.vtuagent.com/v1/webhook/set")! 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()
```