Expand
Get related objects in the same response with expand[] — the syntax, nested paths, what each endpoint expands, and what happens with a bad path.
Objects refer to each other by id: a charge names its customer and its invoice.
Add expand[] to a request and the response carries those related objects in
full, so you don't need a second request to fetch them.
Expand a field
Repeat expand[] once for each field:
curl -g "$WALLET/charges/ch_3b1f9e0a7c2d4e8f9a6b5c4d3e2f1a0b?expand[]=customer&expand[]=invoice" \
-H "Authorization: Bearer ${SECRET_KEY}" \
-H "X-Country: TH"{
"id": "ch_3b1f9e0a7c2d4e8f9a6b5c4d3e2f1a0b",
"object": "charge",
"customer_id": "cus_8d2e41f0c9b84f7e9a1d5b3c7e6f2a10",
"invoice": "in_5e7a2c9d1b3f4a6e8c0d2b4f6a8c0e1d"
}The examples show only the fields that change. An expanded object appears under
the name you expanded. When that field held the id, as a charge's invoice
does, the object takes the id's place. When the id lives in a separate *_id
field, as customer_id does, that field stays and the object is added next to
it.
Expansion works the same on lists: every object on the page is expanded, with one batched lookup per expanded field.
Paths
- Nested objects. Join fields with dots to expand inside an expanded object:
expand[]=invoice.customerreturns the charge's invoice with that invoice's customer expanded. - Depth. A path has at most four fields, such as
invoice.quote.invoice.customer. - Spelling. Each field is lowercase letters, digits and underscores, starting with a letter.
- Overlaps. Paths are merged:
expand[]=invoice&expand[]=invoice.customeris the same asexpand[]=invoice.customer.
What you can expand
| Object | Fields | Endpoints |
|---|---|---|
| Charge | balance, customer, invoice, payment_method | GET /charges, GET /charges/{id}, POST /charges/{id}/capture, POST /charges/{id}/cancel, GET /invoices/{id}/charges |
| Invoice | customer, default_payment_method, quote, subscription | GET /invoices, GET /invoices/{id}, PATCH /invoices/{id}, POST /invoices/create_preview, POST /invoices/{id}/preview |
| Subscription | customer, default_payment_method | GET /subscriptions, GET /subscriptions/{id}, PATCH /subscriptions/{id} |
| Quote | customer, invoice | GET /quotes, GET /quotes/{id}, PATCH /quotes/{id}, POST /quotes/create_preview, POST /quotes/{id}/preview |
| Credit note | customer, invoice, subscription | GET /credit_notes, GET /credit_notes/{id} |
| Payment intent | latest_charge | GET /payment_intents, GET /payment_intents/{id} |
| Payment method | customer | GET /payment_methods, GET /payment_methods/{id} |
| Payout | customer | GET /payouts, GET /payouts/{id} |
| Receipt | customer | GET /receipts, GET /receipts/{id} |
| Refund | charge | GET /refunds, GET /refunds/{id} |
| Balance transaction | balance, account | GET /balance_transactions, GET /balance_transactions/{id}, and the balance_transactions lists under charges, disputes, payouts and refunds |
| Connected account | balance | GET /accounts |
Deeper paths follow the expanded object's own fields:
| Expanded object | Its fields |
|---|---|
| Charge | balance, customer, invoice, payment_method |
| Invoice | customer, default_payment_method, quote, subscription |
| Subscription | customer, default_payment_method |
| Quote | customer, invoice |
| Payment method | customer |
| Balance | none |
| Customer | none |
So GET /refunds/{id}?expand[]=charge.customer returns the refund with its
charge, and the charge with its customer.
When a path is wrong
| Problem | Response |
|---|---|
| More than four fields | 400, expand.depth.exceeded (E1110), param expand[] |
| A field that is not lowercase letters, digits and underscores | 400, expand.segment.invalid (E1111), param expand[] |
| A field the endpoint cannot expand | 400, expand.segment.invalid (E1111), param expand[] |
The message names what the endpoint can expand:
{
"error": {
"type": "invalid_request_error",
"code": "expand.segment.invalid",
"message": "Expandable here: balance, customer, invoice, payment_method; refunds cannot be expanded here.",
"param": "expand[]",
"request_id": "0b9e6c4a-1f2d-4e3b-8a7c-5d6e7f8a9b0c"
}
}If a related object cannot be loaded, the response still succeeds and that field keeps its unexpanded value.
Limits
- Only the endpoints in the table above support
expand[]; any other endpoint refuses it with400. - Webhook payloads are never expanded.
- An expanded object is always complete; you cannot pick some of its fields.