Skip to content

Payment links by API

Create shareable payment pages with an API key: fixed or chosen amounts, single use, limits and expiry.

A payment link is a page you share anywhere (WhatsApp, SMS, an invoice, Instagram, a printed QR code) without building anything. Whoever opens it sees your business, what it's for and the amount, presses Continue and pays by M-Pesa on the hosted checkout. Endpoint details are in the Payment links reference.

These are links you create with an API key (payment_links:write). Links people make in the AutoPayKe app are covered in Payment links.

Creating one

curl -X POST "https://api.autopayke.com/api/v1/payment-links" \
  -H "Authorization: Bearer $AUTOPAYKE_API_KEY" \
  -H "Idempotency-Key: invoice-2041-link" \
  -H "Content-Type: application/json" \
  -d '{
    "amount": 500000,
    "description": "Invoice 2041: October deliveries",
    "reference": "INV-2041",
    "single_use": true,
    "after_payment_url": "https://example.com/paid"
  }'
You sendWhat the payer sees
amountA fixed price, like an invoice or a product.
min_amount and max_amountAn amount box: they choose how much, within your range. Good for donations, tips or topping up.
single_use: trueOne payment, then the link closes. Only one person can be paying at a time, so it can never be paid twice.
max_paymentsCloses after that many payments, like a limited number of tickets.
expires_atCloses at that time (5 minutes to 365 days away).

Getting paid

  1. Each payer who presses Continue gets their own checkout session.
  2. When they pay, you get checkout.session.completed and payment_link.paid. The link's payments_count and amount_collected go up.
  3. If you set after_payment_url, we send the payer there with ?session_id=cs_… added. Otherwise they see a "paid" screen.

List a link's payments with GET /api/v1/payment-links/{id}/payments, or close it any time with POST /api/v1/payment-links/{id}/deactivate.

Treat a payment as received only on the webhook (or a GET), never on the payer reaching your after-payment page.

Testing

Create the link with an apk_test_ key, open its url, press Continue and use the collection sandbox numbers: 0700000001 pays.