#httpsjakeb
1 messages · Page 1 of 1 (latest)
hi 👋
What are you trying to export and from where?
addresses names and phone numbers
just into a csv
because the web feature doesnt allow for phone number export
What "web feature" are you talking about?
the export button
This server is focused on developers coding integrations with Stripe APIs
Are you interacting directly with the stripe APIs?
What API endpoints are you using?
import csv
import stripe
stripe.api_key = ''
def export_stripe_customers():
customers = stripe.Customer.list(limit=100)
with open('stripe_customers.csv', 'w', newline='') as csvfile:
writer = csv.writer(csvfile)
writer.writerow(['Name', 'Email', 'Phone', 'Address'])
for customer in customers:
name = customer.name
email = customer.email
default_source = stripe.Source.retrieve(customer.default_source)
phone = default_source.phone
address = customer.address
writer.writerow([name, email, phone, address])
print('Stripe customers exported to stripe_customers.csv')
export_stripe_customers()
Okay so you are looping through the Customers objects. What seems to be the problem here?
i get this
If you want the default source included you should use the Expand parameter when making the List call: https://stripe.com/docs/expand
Are you certain your customers all have a default_source?
im going to frank i litterlly asked chatgpt and thats what it gave me I have very minial backround in python but i am trying to figure it out but i got stuck and found this
ChatGPT is often wrong about Stripe APIs
And writes very bad code
I would use the expand approach
customers = stripe.Customer.list(limit=100, expand=['default_source'])
As this will return the full default source if it exists
so the default sources is a metedata group ?
No
IT's a field that is expandable
Which is described in the doc I linked
But
Why are you looking there? If you are storing your customers Address and Phone number why are they not in the Customer object? The fields exist.
https://stripe.com/docs/api/customers/object#customer_object-address
so would it be easier to just dump all customer info with no filter on the customer.list
I don't know what you mean by "dump all -- with no filter"
get all info from the obj
Okay sure you can do that
Okay you're getting the Customer data from the Customer List API right?
trying ya
So what is the problem you are encountering?
does it only output 100 at a time ?
Yes that is the maximum number of objects you can return in a single API request
If you need more than that you will need to review our pagination feature. Since you are using stripe-python I recommend using our auto-pagination feature: https://stripe.com/docs/api/pagination/auto
ok ty
am i not doing this right
Hi @rapid echo I'm taking over this thread.
ok thank you
Can you print out customer.shipping and see if it is None?
it gave me none
it should be going thru all of them and exporting the objects to a csv
Do you have the customer ID so I can take a look?
this script goes thru all of them
its not one customer
import csv
import stripe
# Set your Stripe API key
stripe.api_key = ''
def export_stripe_customers():
# Open a CSV file for writing
with open('stripe_customers00.csv', 'w', newline='') as csvfile:
writer = csv.writer(csvfile)
# Write the header row
writer.writerow(['Name', 'Email', 'Phone', 'Address'])
# Retrieve customers using auto-pagination
for customer in stripe.Customer.auto_paging_iter(limit=100):
name = customer.name
email = customer.email
phone = customer.phone
# Retrieve the customer's address
print(customer.shipping)
address = customer.shipping.address.line1
# Write the customer information to the CSV file
writer.writerow([name, email, phone, address])
print('Stripe customers exported to stripe_customers.csv')
# Call the export_stripe_customers function to initiate the export
export_stripe_customers()
is it bc the first customer in the list may not have a shipping address
That's possible, can you print out the customer ID so we can check?
so i think the problem is that some have the box checked the shippis is the same as billing
so from here i guess the best option would be pull the billing addrress
how do i get it to ignore the clients that dont have a billing address
Do a null check?
im not sure ik what u mean
Something like
if customer.shipping is not None:
address = customer.shipping.address.
can i get it to ignore it entirely
if customer.shipping is not None:
address = none
can i do that
It's up to you
would that work
if customer.shipping is not None:
address = none
I don't see it is necessary because the default value of address is already None since it's not initialized yet
I manually added in the addreses that didnt have a billing address a
all set thank you for the assistance
one more question actually
is this thread intergrated to a ticket system or are you in discord itself
No, this discord thread isn't integrated to ticket system.
gotcha