Skip to Content
Paycose Docs
Setup

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.customer returns 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.customer is the same as expand[]=invoice.customer.

What you can expand

ObjectFieldsEndpoints
Chargebalance, customer, invoice, payment_methodGET /charges, GET /charges/{id}, POST /charges/{id}/capture, POST /charges/{id}/cancel, GET /invoices/{id}/charges
Invoicecustomer, default_payment_method, quote, subscriptionGET /invoices, GET /invoices/{id}, PATCH /invoices/{id}, POST /invoices/create_preview, POST /invoices/{id}/preview
Subscriptioncustomer, default_payment_methodGET /subscriptions, GET /subscriptions/{id}, PATCH /subscriptions/{id}
Quotecustomer, invoiceGET /quotes, GET /quotes/{id}, PATCH /quotes/{id}, POST /quotes/create_preview, POST /quotes/{id}/preview
Credit notecustomer, invoice, subscriptionGET /credit_notes, GET /credit_notes/{id}
Payment intentlatest_chargeGET /payment_intents, GET /payment_intents/{id}
Payment methodcustomerGET /payment_methods, GET /payment_methods/{id}
PayoutcustomerGET /payouts, GET /payouts/{id}
ReceiptcustomerGET /receipts, GET /receipts/{id}
RefundchargeGET /refunds, GET /refunds/{id}
Balance transactionbalance, accountGET /balance_transactions, GET /balance_transactions/{id}, and the balance_transactions lists under charges, disputes, payouts and refunds
Connected accountbalanceGET /accounts

Deeper paths follow the expanded object's own fields:

Expanded objectIts fields
Chargebalance, customer, invoice, payment_method
Invoicecustomer, default_payment_method, quote, subscription
Subscriptioncustomer, default_payment_method
Quotecustomer, invoice
Payment methodcustomer
Balancenone
Customernone

So GET /refunds/{id}?expand[]=charge.customer returns the refund with its charge, and the charge with its customer.

When a path is wrong

ProblemResponse
More than four fields400, expand.depth.exceeded (E1110), param expand[]
A field that is not lowercase letters, digits and underscores400, expand.segment.invalid (E1111), param expand[]
A field the endpoint cannot expand400, 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 with 400.
  • Webhook payloads are never expanded.
  • An expanded object is always complete; you cannot pick some of its fields.

What's next

On this page