# API reference

Every K-LINK Pay REST endpoint, grouped by resource, with its parameters, example requests and responses.

## Conventions

- Base URL: `https://api.klinkpay.net`. All paths start with `/v1`.
- Auth: `Authorization: Bearer $KLINK_PAY_API_KEY`. Test keys start with `kp_test_`, live keys with `kp_live_`. See [Authentication and keys](/authentication.md).
- JSON in and out. Amounts are integers in the currency's smallest unit. See [Amounts and currencies](/concepts/currencies.md).
- Errors are `{"error": {"code", "message", "param"}}` with the HTTP status. See [Errors](/concepts/errors.md).
- Send an `Idempotency-Key` header on every `POST`. See [Idempotency](/concepts/idempotency.md).
- Lists are newest first with cursor pagination. See [Pagination](/concepts/pagination.md).
- Pin a version with the `Klink-Version` header. See [Versioning](/concepts/versioning.md).

```bash
curl https://api.klinkpay.net/v1/payments?limit=3 \
  -H "Authorization: Bearer $KLINK_PAY_API_KEY"
```

## Resources

| Resource | What it covers | Endpoints |
|---|---|---|
| [Payments](/api/payments.md) | A payment is one request for money from a customer, paid by scanning a QR code or approving it in a mobile wallet app. | 4 |
| [Refunds](/api/refunds.md) | Request money back for a succeeded payment, in full or in part. | 3 |
| [Events](/api/events.md) | Every change worth knowing about is recorded as an event and sent to your webhook endpoints. | 2 |
| [Balance](/api/balance.md) | What K-LINK Pay holds for you, and when it will be paid out. | 1 |
| [Payouts](/api/payouts.md) | Transfers of your available balance to your bank account. | 2 |
| [Payment links](/api/payment-links.md) | A shareable page where customers pay a fixed amount, without any code on your side. | 4 |
| [Webhook endpoints](/api/webhook-endpoints.md) | Manage the URLs that receive your webhooks from code. | 3 |

## Endpoints

| Endpoint | What it does |
|---|---|
| `POST /v1/payments` | [Create a payment](/api/payments.md#create-a-payment) |
| `GET /v1/payments/:id` | [Retrieve a payment](/api/payments.md#retrieve-a-payment) |
| `GET /v1/payments` | [List payments](/api/payments.md#list-payments) |
| `POST /v1/payments/:id/cancel` | [Cancel a payment](/api/payments.md#cancel-a-payment) |
| `POST /v1/refunds` | [Create a refund](/api/refunds.md#create-a-refund) |
| `GET /v1/refunds/:id` | [Retrieve a refund](/api/refunds.md#retrieve-a-refund) |
| `GET /v1/refunds` | [List refunds](/api/refunds.md#list-refunds) |
| `GET /v1/events/:id` | [Retrieve an event](/api/events.md#retrieve-an-event) |
| `GET /v1/events` | [List events](/api/events.md#list-events) |
| `GET /v1/balance` | [Retrieve the balance](/api/balance.md#retrieve-the-balance) |
| `GET /v1/payouts/:id` | [Retrieve a payout](/api/payouts.md#retrieve-a-payout) |
| `GET /v1/payouts` | [List payouts](/api/payouts.md#list-payouts) |
| `POST /v1/payment_links` | [Create a payment link](/api/payment-links.md#create-a-payment-link) |
| `GET /v1/payment_links/:id` | [Retrieve a payment link](/api/payment-links.md#retrieve-a-payment-link) |
| `GET /v1/payment_links` | [List payment links](/api/payment-links.md#list-payment-links) |
| `POST /v1/payment_links/:id/deactivate` | [Deactivate a payment link](/api/payment-links.md#deactivate-a-payment-link) |
| `POST /v1/webhook_endpoints` | [Create a webhook endpoint](/api/webhook-endpoints.md#create-a-webhook-endpoint) |
| `GET /v1/webhook_endpoints` | [List webhook endpoints](/api/webhook-endpoints.md#list-webhook-endpoints) |
| `DELETE /v1/webhook_endpoints/:id` | [Delete a webhook endpoint](/api/webhook-endpoints.md#delete-a-webhook-endpoint) |

## Related

- [Quick start](/quickstart.md)
- [Webhooks](/guides/webhooks.md)
- [Test mode](/testing.md)
