Skip to navigation

Expanding responses

Objects on https://api.paid.ai/v1 refer to each other by ID: a customer’s parent is the ID of another customer. When you need the referenced object too, ask for it with expand and the response returns the full object in place of the ID, saving you a request per reference.

Use expand to:

  • Save round trips. Get a customer and its parent customer in one call.
  • Read a chain of references. Follow a reference on the object you expanded, up to two references deep.
  • Expand every item of a list. On a list, each path applies to every object in data.

How it works

Add expand to the query string with the path of the field to expand. Repeat it to expand several paths, up to 4 a request.

curl -G https://api.paid.ai/v1/customers/cus_8HqL2xT \
-H "Authorization: Bearer $PAID_API_KEY" \
--data-urlencode "expand=parent"

Without expand, parent is an ID:

{ "parent": "cus_3Fw9KpR" }

With expand=parent, it is the parent customer:

{
"parent": {
"id": "cus_3Fw9KpR",
"object": "customer",
"name": "Northwind Traders"
}
}

A path names fields joined by dots, such as field.nestedField. Each step follows one reference, and a path can go at most two references deep. On a list, paths are relative to each item, so expand=parent on a customer list expands each customer’s parent.

What you can expand

Only some reference fields can be expanded. Each operation that takes expand lists the paths it accepts in the API Reference.

ObjectFieldExpands to
CustomerparentCustomer
CustomerdefaultPaymentMethodPayment method
Payment allocationpaymentPayment

A field that is null stays null when you expand it. Setting a customer’s parent through the API isn’t available yet, so parent is null unless it was set elsewhere.

What an expanded object follows

An expanded object is the same object its own retrieve endpoint returns, at your request’s API version. Expanding it needs what retrieving it needs, so check your key before you add a path:

You expand an object your request can’t retrieveResponse
Your API key lacks the object’s scope403 insufficient_scope, naming the scope to add.
The object is in a beta you didn’t opt in to400 beta_header_required, naming the Paid-Beta value to send.
Your key is scoped to one customer403 customer_key_forbidden, unless that object allows it.

A referenced object that no longer exists, or that your account can’t see, stays an ID. The rest of the response is unchanged.

Errors

A path that the operation doesn’t accept, a path more than two references deep, or more than 4 paths returns 400 invalid_request, with param naming the expand value at fault, such as expand or expand[1]. A request that fails returns nothing else, so fix it and send it again.