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

# Subscribe to purchase events

POST https://api.andel.org/exchange/v1/webhooks/subscriptions
Content-Type: application/json

Reference: https://docs.andel.org/dataexchange/data-exchange-api/webhooks/create-subscription

## Authentication

- `Authorization` header (bearer token, required) — Production machine-to-machine flow. Tokens issued by Descope.

## Servers

- `https://api.andel.org/exchange/v1` (Production, default)
- `https://7403d846-765d-4d63-9e5c-b7f0ab21a354.mock.pstmn.io/exchange/v1` (Postman mock server (sandbox; auth is not enforced))

## Request

### Body (application/json)

- `url` (string, required) — HTTPS endpoint where Andel will POST events.
- `event_types` (list of enum, required)
  - Allowed values: `purchase.created`
- `description` (string, optional) — Human-readable label for this subscription.

## Response

### 201

Subscription created. The response includes the signing secret used to verify webhook payloads.

- `subscription_id` (string, required)
- `url` (string, required)
- `event_types` (list of string, required)
- `created_at` (datetime, required)
- `signing_secret` (string, required) — Secret used to verify the X-Andel-Signature header on webhook deliveries. Returned once at creation.
- `description` (string, optional)

## Examples

### Newly-created subscription

**Request**

```json
undefined
```

**Response**

```json
{
  "subscription_id": "9f1a2b3c-4d5e-6f70-8192-a3b4c5d6e7f8",
  "url": "https://example-pbm.com/webhooks/andel",
  "event_types": [
    "purchase.created"
  ],
  "created_at": "2026-05-13T18:25:00Z",
  "signing_secret": "whsec_REPLACE_ME_AT_GO_LIVE",
  "description": "Production purchases stream"
}
```

**SDK Code**

```python Newly-created subscription
import requests

url = "https://api.andel.org/exchange/v1/webhooks/subscriptions"

headers = {"Authorization": "Bearer <token>"}

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

print(response.json())
```

```javascript Newly-created subscription
const url = 'https://api.andel.org/exchange/v1/webhooks/subscriptions';
const options = {method: 'POST', headers: {Authorization: 'Bearer <token>'}};

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

```go Newly-created subscription
package main

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

func main() {

	url := "https://api.andel.org/exchange/v1/webhooks/subscriptions"

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

	req.Header.Add("Authorization", "Bearer <token>")

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

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

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

}
```

```ruby Newly-created subscription
require 'uri'
require 'net/http'

url = URI("https://api.andel.org/exchange/v1/webhooks/subscriptions")

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

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'

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

```java Newly-created subscription
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.andel.org/exchange/v1/webhooks/subscriptions")
  .header("Authorization", "Bearer <token>")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.andel.org/exchange/v1/webhooks/subscriptions', [
  'headers' => [
    'Authorization' => 'Bearer <token>',
  ],
]);

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

```csharp Newly-created subscription
using RestSharp;

var client = new RestClient("https://api.andel.org/exchange/v1/webhooks/subscriptions");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
IRestResponse response = client.Execute(request);
```

```swift Newly-created subscription
import Foundation

let headers = ["Authorization": "Bearer <token>"]

let request = NSMutableURLRequest(url: NSURL(string: "https://api.andel.org/exchange/v1/webhooks/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()
```

### Subscribe to purchase.created

**Request**

```json
{
  "url": "https://example-pbm.com/webhooks/andel",
  "event_types": [
    "purchase.created"
  ],
  "description": "Production purchases stream"
}
```

**Response**

```json
{
  "subscription_id": "9f1a2b3c-4d5e-6f70-8192-a3b4c5d6e7f8",
  "url": "https://example-pbm.com/webhooks/andel",
  "event_types": [
    "purchase.created"
  ],
  "created_at": "2026-05-13T18:25:00Z",
  "signing_secret": "whsec_REPLACE_ME_AT_GO_LIVE",
  "description": "Production purchases stream"
}
```

**SDK Code**

```python Subscribe to purchase.created
import requests

url = "https://api.andel.org/exchange/v1/webhooks/subscriptions"

payload = {
    "url": "https://example-pbm.com/webhooks/andel",
    "event_types": ["purchase.created"],
    "description": "Production purchases stream"
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript Subscribe to purchase.created
const url = 'https://api.andel.org/exchange/v1/webhooks/subscriptions';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"url":"https://example-pbm.com/webhooks/andel","event_types":["purchase.created"],"description":"Production purchases stream"}'
};

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

```go Subscribe to purchase.created
package main

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

func main() {

	url := "https://api.andel.org/exchange/v1/webhooks/subscriptions"

	payload := strings.NewReader("{\n  \"url\": \"https://example-pbm.com/webhooks/andel\",\n  \"event_types\": [\n    \"purchase.created\"\n  ],\n  \"description\": \"Production purchases stream\"\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 Subscribe to purchase.created
require 'uri'
require 'net/http'

url = URI("https://api.andel.org/exchange/v1/webhooks/subscriptions")

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  \"url\": \"https://example-pbm.com/webhooks/andel\",\n  \"event_types\": [\n    \"purchase.created\"\n  ],\n  \"description\": \"Production purchases stream\"\n}"

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

```java Subscribe to purchase.created
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.andel.org/exchange/v1/webhooks/subscriptions")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"url\": \"https://example-pbm.com/webhooks/andel\",\n  \"event_types\": [\n    \"purchase.created\"\n  ],\n  \"description\": \"Production purchases stream\"\n}")
  .asString();
```

```php Subscribe to purchase.created
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.andel.org/exchange/v1/webhooks/subscriptions', [
  'body' => '{
  "url": "https://example-pbm.com/webhooks/andel",
  "event_types": [
    "purchase.created"
  ],
  "description": "Production purchases stream"
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp Subscribe to purchase.created
using RestSharp;

var client = new RestClient("https://api.andel.org/exchange/v1/webhooks/subscriptions");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"url\": \"https://example-pbm.com/webhooks/andel\",\n  \"event_types\": [\n    \"purchase.created\"\n  ],\n  \"description\": \"Production purchases stream\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Subscribe to purchase.created
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "url": "https://example-pbm.com/webhooks/andel",
  "event_types": ["purchase.created"],
  "description": "Production purchases stream"
] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://api.andel.org/exchange/v1/webhooks/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()
```