Sign in
An image of the Stripe logo
Create account
Sign in
Home
Payments
Business operations
Financial services
Developer tools
Security
All products
Home
Payments
Business operations
Home
Payments
Business operations
Financial services
Developer tools
Support
Overview
Get started
Quickstarts
Stripe Shell
Stripe CLI
Dashboard
Stripe for Visual Studio Code
Webhooks
File uploads
Error handling
API
Tour
Keys
Libraries
Upgrades
Rate limits
Card testing
Expanding responses
Use cases
Domains and IP addresses
Search
Building With Stripe
React Stripe.js
Prebuilt iOS UI
Prebuilt Android UI
Extensions
Connectors
Samples
Checklist
Feedback
HomeDeveloper tools

Expanding responses

Learn how to reduce the number of requests you make to the Stripe API by expanding objects in responses.

This guide describes how to request additional properties from the API. You will learn to modify your requests to include:

  • properties from related objects
  • properties from distantly related objects
  • additional properties on all objects in a list
  • properties that aren’t included by default in a response

How it works

The Stripe API is organized into resources represented by objects with state, configuration, and contextual properties. These objects all have unique IDs that you can use to retrieve, update, and delete them. The API also uses these IDs to link related objects together. A Checkout Session, for example, links to a Customer by the Customer ID.

{ "id": "cs_test_KdjLtDPfAjT1gq374DMZ3rHmZ9OoSlGRhyz8yTypH76KpN4JXkQpD2G0", "object": "checkout.session", ... "customer": "cus_HQmikpKnGHkNwW", ... }

In cases where you need information from a linked object, you can retrieve the linked object in a new call using its ID. However, this approach requires two API requests to access just one value. If you need information from multiple linked objects, each would also require separate requests, which all adds to the latency and complexity of your application.

The API has an Expand feature that allows you to retrieve linked objects in a single call, effectively replacing the object ID with all its properties and values. For example, say you wanted to access details on a customer tied to a given Checkout Session. You would retrieve the Checkout Session and pass the customer property to the expand array, which tells Stripe to include the entire Customer object in the response:

Terminal
curl https://api.stripe.com/v1/checkout/sessions/cs_test_KdjLtDPfAjT1gq374DMZ3rHmZ9OoSlGRhyz8yTypH76KpN4JXkQpD2G0 \ -u
sk_test_4eC39HqLyjWDarjtT1zdp7dc
: \ -d "expand[]"=customer \ -G

Which returns the Checkout Session with the full Customer object instead of its ID:

{ "id": "cs_test_KdjLtDPfAjT1gq374DMZ3rHmZ9OoSlGRhyz8yTypH76KpN4JXkQpD2G0", "object": "checkout.session", ... "customer": { "id": "cus_HQmikpKnGHkNwW", "object": "customer", ... "metadata": { "user_id": "user_xyz" }, ... } }

Not all properties can be expanded. The API reference marks expandable properties with the “Expandable” label.

Expanding multiple properties

To expand multiple properties in one call, add additional items to the expand array. For example, if you want to expand both the customer and the payment_intent for a given Checkout Session, you would pass expand an array with both the customer and payment_intent strings:

Terminal
curl https://api.stripe.com/v1/checkout/sessions/cs_test_KdjLtDPfAjT1gq374DMZ3rHmZ9OoSlGRhyz8yTypH76KpN4JXkQpD2G0 \ -u
sk_test_4eC39HqLyjWDarjtT1zdp7dc
: \ -d "expand[]"=customer \ -d "expand[]"=payment_intent \ -G

Expanding multiple levels

If the value you want is nested deeply across multiple linked resources, you can reach it by recursively expanding using dot notation. For instance, if you needed to know the type of payment method that was used for a given Checkout Session, you would first retrieve the Checkout Session’s payment intent, then retrieve the payment intent’s linked payment method to get its type. With expand, you can do this in one call:

Terminal
curl https://api.stripe.com/v1/checkout/sessions/cs_test_KdjLtDPfAjT1gq374DMZ3rHmZ9OoSlGRhyz8yTypH76KpN4JXkQpD2G0 \ -u
sk_test_4eC39HqLyjWDarjtT1zdp7dc
: \ -d "expand[]"="payment_intent.payment_method" \ -G

Which returns the Checkout Session with the full PaymentIntent and PaymentMethod objects instead of their IDs:

{ "id": "cs_test_KdjLtDPfAjT1gq374DMZ3rHmZ9OoSlGRhyz8yTypH76KpN4JXkQpD2G0", "object": "checkout.session", ... "mode": "payment", "payment_intent": { "id": "pi_1GkXXDLHughnNhxyLlsnvUuY", "object": "payment_intent", "amount": 100, ... "charges": {...}, "client_secret": "pi_1GkXXDLHughnNhxyLlsnvUuY_secret_oLbwpm0ME0ieJ9Aykz2SwKzj5", ... "payment_method": { "id": "pm_1GkXXuLHughnNhxy8xpAdGtf", "object": "payment_method", "billing_details": {...}, "card": {...},

Expansions have a maximum depth of four levels. Meaning that an expand string can contain no more than four properties: property1.property2.property3.property4.

Expanding properties in lists

When the API returns a list of objects, you can use the data keyword to expand a given property on each object in that list. For example, say you need information about the payment methods used by one of your customers. To get this information, you would list the customer’s PaymentIntents, which returns an object with the following structure:

{ "object": "list", "data": [ { "id": "pi_1GrvBKLHughnNhxy6N28q8gt", "object": "payment_intent", "amount": 1000, ... "payment_method": "pm_1GrvBxLHughnNhxyJjtBtHcc", ... },

All lists returned in the API have the above structure, where the data property contains the array of objects being listed. You can use the data keyword in any position in an expand string to move the expand cursor into the list.

Rather than looping through each payment intent in the list and retrieving the linked payment methods in separate calls, you can expand all the payment methods at once using the data keyword:

Terminal
curl https://api.stripe.com/v1/payment_intents \ -u
sk_test_4eC39HqLyjWDarjtT1zdp7dc
: \ -d customer=cus_HQmikpKnGHkNwW \ -d "expand[]"="data.payment_method" \ -G

The list then includes the full payment method object on each payment intent:

{ "object": "list", "data": [ { "id": "pi_1GrvBKLHughnNhxy6N28q8gt", "object": "payment_intent", "amount": 1000, ... "payment_method": { "id": "pm_1GrvBxLHughnNhxyJjtBtHcc", "object": "payment_method", "billing_details": {...}, "card": { "brand": "visa", ...

Expanding responses has performance implications. To keep requests fast, try to limit many nested expansions on list requests.

Requesting includable properties with Expand

In some cases, resources have properties that aren’t included by default. One example is the Checkout Session’s line_items property, which is only included in responses if requested using the expand parameter, for example:

Terminal
curl https://api.stripe.com/v1/checkout/sessions/cs_test_KdjLtDPfAjT1gq374DMZ3rHmZ9OoSlGRhyz8yTypH76KpN4JXkQpD2G0 \ -u
sk_test_4eC39HqLyjWDarjtT1zdp7dc
: \ -d "expand[]"=line_items \ -G

Like other expandable properties, the API reference marks properties that are includable with the “Expandable” label.

Using Expand with Webhooks

You can’t receive webhook events with properties auto-expanded. Objects sent in events are always in their minimal form. To access nested values in expandable properties, you must retrieve the object in a separate call within your webhook handler.

Was this page helpful?
Questions? Contact us.
View developer tutorials on YouTube.
Check out our product changelog.
Powered by Markdoc
You can unsubscribe at any time. Read our privacy policy.
On this page
How it works
Expanding multiple properties
Expanding multiple levels
Expanding properties in lists
Requesting includable properties with Expand
Using Expand with Webhooks
Stripe Shell
Test mode
▗▄ ▄▟█ █▀▀ ▗▟████▙▖ ██████ ███▗▟█ ███ ███▗▟██▙▖ ▗▟█████▙▖ ███▖ ▀▀ ███ ███▀▀▀ ███ ███▀ ███ ███ ███ ▝▜████▙▖ ███ ███ ███ ███ ███ █████████ ▄▄ ▝███ ███ ▄ ███ ███ ███▄ ███ ███ ▄▄ ▝▜████▛▘ ▝▜███▛ ███ ███ ███▝▜██▛▘ ▝▜█████▛▘ ███ ▀▘
Welcome to the Stripe Shell! Stripe Shell is a browser-based shell with the Stripe CLI pre-installed. Login to Stripe docs and press Control + Backtick on your keyboard to start managing your Stripe resources in test mode. - View supported commands: - Find webhook events: - Listen for webhook events: - Call Stripe APIs: stripe [api resource] [operation] (e.g. )
The Stripe Shell is best experienced on desktop.
$