#nikivi_api
1 messages ¡ Page 1 of 1 (latest)
đ Welcome to your new thread!
â˛ď¸ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
âąď¸ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
đ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1282944076525867058
đ Have more to share? Add more details, code, screenshots, videos, etc. below.
https://docs.stripe.com/api/subscriptions/list you can call this API to retrieve all subscriptions, and get the customers associated with these subscriptions
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
this is sk_test i see
do i change this to live value right
as i want to get things from production stripe
Sure you can do that
No, you should use the private API key to retrieve subscriptions
i.e., sk_live_xxx
The max of limit is 100, if you have more than 100 subscription, you should paginate https://docs.stripe.com/api/pagination
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
import Stripe from "stripe"
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!)
async function getStripePayingUsers() {
const subscriptions = await stripe.subscriptions.list()
const payingCustomers = []
for (const subscription of subscriptions.data) {
if (subscription.status === "active") {
const customer = await stripe.customers.retrieve(subscription.customer as string)
payingCustomers.push(customer)
}
}
console.log(payingCustomers, "paying customers")
console.log(subscriptions, "subs")
}
yea we have more than 100
a ok will try paginate
trying to get how to get the customer associated as the return is quite messy
from subscriptions
like there is req status there too
i just want to get the data out
is it possible to get return from stripe without that request details
just the data
i.e.
async function getStripePayingUsers() {
const subscriptions = await stripe.subscriptions.list()
const payingCustomers = []
for (const subscription of subscriptions.data) {
if (subscription.status === "active") {
const customer = await stripe.customers.retrieve(subscription.customer as string)
payingCustomers.push(customer)
}
}
console.log(payingCustomers, "paying customers")
}
if i log this, its hard to see what is even being returned
What do you mean by "without that request details" ?
I think you can just use a map function to filter out the data
i get all this stuff
im looking at returned customer object
how do i know they are paying sub
none of this helps me know if they are paying or not 
maybe balance
Check the customer's delinquent field https://docs.stripe.com/api/customers/object#customer_object-delinquent
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Any invoice payment failures, or past-due invoices associated with the customer will set delinquent to true.
trying to figure out types now
ok i failed to add types
@vagrant lake but check this
async function getStripePayingUsers() {
const subscriptions = await stripe.subscriptions.list()
const payingCustomers = []
for (const subscription of subscriptions.data) {
if (subscription.status === "active") {
const customer = await stripe.customers.retrieve(subscription.customer as string)
// @ts-ignore
if (!customer.delinquent) {
payingCustomers.push(customer)
}
}
}
console.log(
// @ts-ignore
payingCustomers.map(c => ({ id: c.id, name: c.name, email: c.email })),
"non-delinquent customers"
)
}
this returns too little users
it returns 8
but i have more than 100 paying users
100%
i have feeling its due to pagination
but i don't get how to get pagination over 1000 elements
https://docs.stripe.com/api/pagination/auto try using auto pagination
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
that worked, thank you @vagrant lake