Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to query for datetime ranges with the Stripe API?

Using the Stripe API, I'd like to be able to query for date ranges or, failing that, dates that are greater than or less than some arbitrary date.

I know that I can query for something based on an exact date, e.g.,:

https://api.stripe.com/v1/events?created=1336503409

But I want something along the lines of...

# Search for events where `created` is greater than the epoch time: 1336503400
https://api.stripe.com/v1/events?created__gt=1336503400 
like image 768
Chris W. Avatar asked May 24 '12 17:05

Chris W.


People also ask

What is stripe REST API?

The Stripe API allows developers to access the functionality of Stripe. Some example API methods include sending invoices, accepting payments, managing subscription billing, and editing and managing account information.

How to get data from a resource in stripe API?

Stripe API contains many resources (datasets). In this function, we can pass in the name of the resource to get the corresponding data. For example, the basic format to get the subscription data is stripe.Subscription.list (). We use getattr in our function in order to include resource as a parameter in the function.

Is there an API for stripe billing analytics dashboard in Python?

Stripe Billing Analytics Dashboard provides a summarized view of your account, which provides a lot of useful information like MRR, churn, and so on. Unfortunately, there is not an API for the Stripe Billing Analytics Dashboard (I actually contacted the support and asked about this). So, I can’t get the dashboard out to Python directly.

How do I get a stripe API key?

Next, you will need an API key to access the stripe API. Go to stripe.com — Devlopers — API keys, and then click “+ Create secret key” to get an API key. Then you can define the stripe api_key and also don’t forget to define the api_version.

What is stripe and how to install it?

Stripe is an online payment company that offers software and APIs for processing payments and business management. I love that Stripe has different APIs for different languages, which makes people’s lives a lot easier. I primarily use the Stripe Python API. To install: You can also do conda install stripe.


3 Answers

Yes. From https://stripe.com/docs/api?lang=curl#list_events

created: A filter on the list based on the events created date. The value can be a string with an exact UTC timestamp, or it can be a dictionary with the following options:

gt (optional) Return values should have been created after this timestamp.

gte (optional) Return values should have been created after or equal to this timestamp.

lt (optional) Return values should have been created before this timestamp.

lte (optional) Return values should have been created before or equal to this timestamp.

So with curl, you can build a request like this:

curl "https://api.stripe.com/v1/events?created%5Blt%5D=1337923293" \
 -u ${YOUR_API_KEY}:

The unescaped query parameter is created[lt]=1337923293.

like image 138
anurag Avatar answered Oct 12 '22 13:10

anurag


If you're looking how to do so with the ruby client, here it is:

Stripe::Charge.all(limit: 100, 'created[lt]' => timestamps })
like image 24
Gab Avatar answered Oct 12 '22 12:10

Gab


Along the same lines. You can achieve the same thing with the Python client like so:

import stripe
from datetime import datetime, timedelta

my_date = '1/31/2011'
my_timestamp = datetime.strptime(my_date, "%m/%d/%Y").timestamp()


stripe.Charge.all(created={'lt': my_timestamp})
like image 37
Rob Carpenter Avatar answered Oct 12 '22 12:10

Rob Carpenter