Quickstart

Send your first event and create an invoice in under 5 minutes
View as Markdown

This guide walks you through the core Afternoon workflow: authenticating, creating a customer, sending a billable event, and generating an invoice.

Prerequisites

1. Create a customer

$curl -X POST https://api.afternoon.co/v1/customers \
> -H "Authorization: Bearer ak_live_YOUR_API_KEY" \
> -H "Content-Type: application/json" \
> -d '{
> "name": "Acme Corp",
> "email": "billing@acme.com",
> "external_id": "cust_123"
> }'
Response
1{
2 "success": true,
3 "customer": {
4 "id": "cm5x9z8nv0000h85r7l9p2k1m",
5 "name": "Acme Corp",
6 "email": "billing@acme.com",
7 "external_id": "cust_123",
8 ...
9 },
10 "request_id": "req_abc123"
11}

Save the customer.id — you’ll need it in the next steps.

2. Send a billable event

$curl -X POST https://api.afternoon.co/v1/events/ingest \
> -H "Authorization: Bearer ak_live_YOUR_API_KEY" \
> -H "Content-Type: application/json" \
> -d '{
> "events": [
> {
> "event_name": "api.request",
> "idempotency_key": "evt_abc123xyz",
> "customer_id": "cm5x9z8nv0000h85r7l9p2k1m",
> "timestamp": "2024-01-15T10:30:00Z",
> "properties": {
> "tokens": 150,
> "model": "gpt-4"
> }
> }
> ]
> }'
Response
1{
2 "success": true,
3 "accepted": 1,
4 "request_id": "req_def456"
5}

Events are queued for asynchronous processing. Use the idempotency_key to safely retry requests without creating duplicate events.

3. Create a draft invoice

$curl -X POST https://api.afternoon.co/v1/invoices \
> -H "Authorization: Bearer ak_live_YOUR_API_KEY" \
> -H "Content-Type: application/json" \
> -d '{
> "customer_id": "cm5x9z8nv0000h85r7l9p2k1m",
> "collection_method": "send_invoice",
> "days_until_due": 30,
> "line_items": [
> {
> "description": "API calls — Jan 2024",
> "quantity": 1,
> "unit_amount_cents": 5000
> }
> ]
> }'
Response
1{
2 "success": true,
3 "invoice": {
4 "id": "cm5x9z8nv0001h85r7l9p2k2m",
5 "status": "draft",
6 "total_cents": 5000,
7 "line_items": [...],
8 ...
9 },
10 "request_id": "req_ghi789"
11}

4. Finalize the invoice

Finalizing transitions the invoice from draft to open, assigns an invoice number, and generates a public payment URL.

$curl -X POST https://api.afternoon.co/v1/invoices/cm5x9z8nv0001h85r7l9p2k2m/finalize \
> -H "Authorization: Bearer ak_live_YOUR_API_KEY"
Response
1{
2 "success": true,
3 "invoice": {
4 "id": "cm5x9z8nv0001h85r7l9p2k2m",
5 "status": "open",
6 "invoice_number": "INV-0001",
7 "public_invoice_url": "https://pay.afternoon.co/inv/abc123",
8 ...
9 },
10 "request_id": "req_jkl012"
11}

Next steps