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.
About the author
Matthew Ling (@mattling_dev) is a Developer Advocate at Stripe. Matt loves to tinker with new technology, adores Ruby and coffee and also moonlighted as a pro music photographer. His photo site is at matthewling.com and developer site is at mattling.dev.
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
Top comments (2)
Using any query service, it is a reasonable expectation when searching within a resource, for example, customers, to query key fundamental fields such as balance:
query: "balance>0"
Reviewing available Query fields for customers, this query is not possible.
Field
balanceis an unsupported search field for resource
customers.
Why not?
Is there another alternative to perform queries with unsupported search fields without prohibitive cost?
Stripe search queries are great! However, if one is using user input as part of the query, it is important to escape the input first. I wrote an article about it here: dev.to/soerenmetje/injections-in-s...