Getting started with the Search API
What you’ll learn
If you’ve worked with the Stripe API before, you know that you can retrieve your resources like Customers and Payment Intents by using list API endpoints and then paging through the resulting data. You may have even used the really useful auto-pagination features — that are included in all of our officially supported client libraries — to page and filter objects to be used in your system.
In this episode you’ll learn how to leverage the new Search API and its comprehensive query language to query the API directly for your Stripe resources. This new API enables you to build complex interfaces to your data. For example, you might want to build a search tool for listing failed Charges, or Customers with a specific email address for support cases.
Now for searchable resources, you can issue a search query in one API call and retrieve the objects you’re interested in. Here’s a simple example in Ruby:
results = Stripe::PaymentIntent.search(query: 'amount:1000')
results.each do |result|
p %(#{result.id} #{result.amount} #{result.currency})
end
Auto-pagination is also available on search results using our client libraries.
Prerequisites
If you’d like to follow along, you’ll need a Stripe account which you can sign up for here.
Table of contents
- 00:00 Introduction
- 00:58 Anatomy of a query
- 01:39 Searching for nested objects
- 01:51 Using compound clauses
- 02:21 Searching for strings
- 02:50 Field types
- 03:13 Searching for numeric values
- 03:42 Searching for metadata
- 04:15 Conclusion
What to watch next
To learn about auto-pagination there is a list of videos in many languages on our YouTube channel.
Stay connected
In addition, you can stay up to date with Stripe in a few ways:
📣 Follow us on Twitter
💬 Join the official Discord server
📺 Subscribe to our Youtube channel
📧 Sign up for the Dev Digest
📣 Author @mattling_dev