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

# Subscribe to purchase events

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

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

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: dataexchange
  version: 1.0.0
paths:
  /webhooks/subscriptions:
    post:
      operationId: create-subscription
      summary: Subscribe to purchase events
      tags:
        - subpackage_webhooks
      parameters:
        - name: Authorization
          in: header
          description: Production machine-to-machine flow. Tokens issued by Descope.
          required: true
          schema:
            type: string
      responses:
        '201':
          description: >-
            Subscription created. The response includes the signing secret used
            to verify webhook payloads.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SubscriptionWithSecret'
        '400':
          description: Invalid request.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Problem'
        '401':
          description: Missing or invalid token.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Problem'
        '500':
          description: Unexpected server error.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Problem'
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SubscriptionCreate'
servers:
  - url: https://api.andel.org/exchange/v1
    description: Production
  - url: https://7403d846-765d-4d63-9e5c-b7f0ab21a354.mock.pstmn.io/exchange/v1
    description: Postman mock server (sandbox; auth is not enforced)
components:
  schemas:
    SubscriptionCreateEventTypesItems:
      type: string
      enum:
        - purchase.created
      title: SubscriptionCreateEventTypesItems
    SubscriptionCreate:
      type: object
      properties:
        url:
          type: string
          format: uri
          description: HTTPS endpoint where Andel will POST events.
        event_types:
          type: array
          items:
            $ref: '#/components/schemas/SubscriptionCreateEventTypesItems'
        description:
          type: string
          description: Human-readable label for this subscription.
      required:
        - url
        - event_types
      title: SubscriptionCreate
    SubscriptionWithSecret:
      type: object
      properties:
        subscription_id:
          type: string
          format: uuid
        url:
          type: string
          format: uri
        event_types:
          type: array
          items:
            type: string
        description:
          type: string
        created_at:
          type: string
          format: date-time
        signing_secret:
          type: string
          description: >-
            Secret used to verify the X-Andel-Signature header on webhook
            deliveries. Returned once at creation.
      required:
        - subscription_id
        - url
        - event_types
        - created_at
        - signing_secret
      title: SubscriptionWithSecret
    Problem:
      type: object
      properties:
        type:
          type: string
          format: uri
        title:
          type: string
        status:
          type: integer
        detail:
          type: string
        instance:
          type: string
        andel_request_id:
          type: string
          description: Pass to support to trace this request.
      required:
        - type
        - title
        - status
      description: RFC 9457 problem details with Andel extensions.
      title: Problem
  securitySchemes:
    andelDescopeClientCredentials:
      type: http
      scheme: bearer
      description: Production machine-to-machine flow. Tokens issued by Descope.

```

## 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>",
    "Content-Type": "application/json"
}

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>', 'Content-Type': 'application/json'},
  body: undefined
};

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>")
	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 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>'
request["Content-Type"] = 'application/json'

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>")
  .header("Content-Type", "application/json")
  .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>',
    'Content-Type' => 'application/json',
  ],
]);

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>");
request.AddHeader("Content-Type", "application/json");
IRestResponse response = client.Execute(request);
```

```swift Newly-created subscription
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]

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