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.
Without expand, parent is an ID:
With expand=parent, it is the parent customer:
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.
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:
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.