Getting started with the Search API
Tags: stripe, search, tutorial, webdev
Published: 2022-06-08 12:16:28

{% youtube aIz-55XeWYo %}

## 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](https://stripe.com/docs/api/pagination/auto) 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](https://stripe.com/docs/search) and its comprehensive [query language](https://stripe.com/docs/search#search-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](https://stripe.com/docs/search#query-fields-for-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:

```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](https://dashboard.stripe.com/register).

## Table of contents
* 00:00 [Introduction](https://www.youtube.com/watch?v=aIz-55XeWYo)
* 00:58 [Anatomy of a query](https://www.youtube.com/watch?v=aIz-55XeWYo&t=58s)
* 01:39 [Searching for nested objects](https://www.youtube.com/watch?v=aIz-55XeWYo&t=90s)
* 01:51 [Using compound clauses](https://www.youtube.com/watch?v=aIz-55XeWYo&t=111s)
* 02:21 [Searching for strings](https://www.youtube.com/watch?v=aIz-55XeWYo&t=141s)
* 02:50 [Field types](https://www.youtube.com/watch?v=aIz-55XeWYo&t=170s)
* 03:13 [Searching for numeric values](https://www.youtube.com/watch?v=aIz-55XeWYo&t=193s)
* 03:42 [Searching for metadata](https://www.youtube.com/watch?v=aIz-55XeWYo&t=222s)
* 04:15 [Conclusion](https://www.youtube.com/watch?v=aIz-55XeWYo&t=255s)

## What to watch next

To learn about auto-pagination there is a [list of videos](https://www.youtube.com/c/StripeDevelopers/search?query=pagination) in many languages on our YouTube channel.

### About the author

![Matthew Ling](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c8rpgkqr91ivs8sxr73g.png) 

Matthew Ling ([@mattling_dev](@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](https://matthewling.com) and developer site is at [mattling.dev](https://mattling.dev).


### Stay connected

In addition, you can stay up to date with Stripe in a few ways:

📣 Follow us on [Twitter](https://twitter.com/StripeDev)
💬 Join the official [Discord server](https://stripe.com/go/developer-chat)
📺 Subscribe to our [Youtube channel](https://www.youtube.com/StripeDevelopers)
📧 Sign up for the [Dev Digest](https://go.stripe.global/dev-digest)