Expand
Get a related object inside a response instead of making a second call.
Many billing objects hold the ID of a related object, such as customerId on a subscription. Ask for the whole object with
expand[] and it comes back in the same response.
How it works
Add expand[] to the query. The ID field keeps its value, and the object appears next to it without the Id. So
customerId stays and customer is added.
curl "https://api-malipo.flex.co.tz/api/v1/subscriptions/<id>?expand[]=customer&expand[]=items.price" \
-H "Authorization: Bearer <token>"{
"id": "...",
"customerId": "...",
"customer": { "id": "...", "name": "Amina" },
"items": [
{
"priceId": "...",
"price": { "id": "...", "currency": "TZS", "unitAmount": 10000 }
}
]
}- Repeat
expand[]for each path. - A path may go through several objects, with dots:
items.price.productembeds the product of each item's price. A path has up to 4 levels. - An expanded object has the same fields as the response of retrieving it. It is always your own object, in the same mode.
- Without
expand[], the response has only the IDs. An expanded field that has no object isnull.
Lists
On a list, start every path with data., because the objects are in the data array.
curl "https://api-malipo.flex.co.tz/api/v1/invoices?status=open&expand[]=data.customer" \
-H "Authorization: Bearer <token>"A path without data. on a list is refused.
What you can expand
| Endpoint | Paths |
|---|---|
| Retrieve a subscription | customer, items.price and deeper, such as items.price.product |
| List subscriptions | data.customer, data.items.price |
| Retrieve a price | product |
| List prices | data.product |
| Retrieve an invoice | customer, subscription, subscription.customer, subscription.items.price |
| List invoices | data.customer, data.subscription, data.subscription.customer, data.subscription.items.price |
| Retrieve a credit note | invoice, invoice.customer, invoice.subscription |
| List the credit notes of an invoice | invoice, invoice.customer, invoice.subscription |
An expanded invoice has the shape the invoice list shows. It has no pay link and no lines.
When a path is refused
A path that is not offered, is empty, or has more than 4 levels answers 400 with the code parameter_invalid. param
holds the path you sent, and message says why:
{
"error": {
"type": "invalid_request_error",
"code": "parameter_invalid",
"message": "customer.nope cannot be expanded here",
"param": "customer.nope",
"requestId": "req_4f1c2a9e8b7d4c3a9f0e1d2c3b4a5f6e"
}
}A path such as items that stops at a list of objects with nothing to embed is refused too. Use items.price.
Webhooks
Webhook events are never expanded. An event holds the object as it was when the event happened. To get a related object,
retrieve it, or retrieve the object again with expand[].