# Purchase validation

Verify a purchase code a buyer gives you — the core of any licence system you run yourself. Returns the purchase details when the code belongs to one of **your** items and is still active; otherwise 404. Needs `purchases:validate`.

> **Tip:** Selling software that should check its own licence? [Licence activation](https://sellmycode.net/api-docs/licence-activation.md) does it without a token and with signed answers — usually the better choice.

`POST /api/purchases/validation`

| Parameter | Type | Description |
|---|---|---|
| `purchase_code` *required* | string | The code from the buyer (shown on their Purchases page and licence certificate) |
```bash
curl -X POST https://sellmycode.net/api/purchases/validation \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d "purchase_code=BUYER_PURCHASE_CODE"
```
```php
// licence check from your app / plugin
$ch = curl_init('https://sellmycode.net/api/purchases/validation');
curl_setopt_array($ch, [
    CURLOPT_POST => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => ['Authorization: Bearer YOUR_API_KEY'],
    CURLOPT_POSTFIELDS => http_build_query(['purchase_code' => $code]),
]);
$res = json_decode(curl_exec($ch), true);
$valid = ($res['status'] ?? '') === 'success';
```
```node
// Node.js 18+ (built-in fetch)
const res = await fetch('https://sellmycode.net/api/purchases/validation', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ purchase_code: code }),
});
const data = await res.json();
const valid = res.ok && data.status === 'success';
```
```python
# Python 3 + requests
import requests

res = requests.post(
    'https://sellmycode.net/api/purchases/validation',
    headers={'Authorization': 'Bearer YOUR_API_KEY'},
    data={'purchase_code': code},
    timeout=10,
)
valid = res.status_code == 200 and res.json().get('status') == 'success'
```
```json
{
  "status": "success",
  "buyer": "johndoe",
  "license_blocked": false,
  "item": {
    "purchase_code": "8f14e45f-ce95-41d8-a2b6-72e5f13d81a7",
    "license_type": "Regular",
    "price": 29.0,
    "currency": "USD",
    "item": { "…item fields…": "" },
    "supported_until": "2026-12-01T00:00:00+00:00",
    "download_expiry": "2026-08-01T00:00:00+00:00",
    "downloaded": true,
    "date": "2026-07-01T09:30:00+00:00"
  }
}
```
> **Warning:** A 404 is returned for BOTH an unknown code and a refunded or blocked purchase — treat any non-200 as "licence invalid".

---
Source: https://sellmycode.net/api-docs/purchase-validation
