#httpsjakeb

1 messages · Page 1 of 1 (latest)

sand lilyBOT
frank coral
#

hi 👋

What are you trying to export and from where?

rapid echo
#

addresses names and phone numbers

#

just into a csv

#

because the web feature doesnt allow for phone number export

frank coral
#

What "web feature" are you talking about?

rapid echo
#

the export button

frank coral
#

This server is focused on developers coding integrations with Stripe APIs

#

Are you interacting directly with the stripe APIs?

rapid echo
#

I am having problems using the api to export the client list

#

yes

frank coral
#

What API endpoints are you using?

rapid echo
#

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()

frank coral
#

Okay so you are looping through the Customers objects. What seems to be the problem here?

rapid echo
#

i get this

frank coral
#

Are you certain your customers all have a default_source?

rapid echo
#

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

frank coral
#

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

rapid echo
#

so the default sources is a metedata group ?

frank coral
#

No

#

IT's a field that is expandable

#

Which is described in the doc I linked

#

But

rapid echo
#

so would it be easier to just dump all customer info with no filter on the customer.list

frank coral
#

I don't know what you mean by "dump all -- with no filter"

rapid echo
#

get all info from the obj

frank coral
#

Okay sure you can do that

rapid echo
#

how can i do that

#

do i have to manually input each feild \

#

each string i mean

frank coral
#

Okay you're getting the Customer data from the Customer List API right?

rapid echo
#

trying ya

frank coral
#

So what is the problem you are encountering?

rapid echo
#

does it only output 100 at a time ?

frank coral
#

Yes that is the maximum number of objects you can return in a single API request

rapid echo
#

ok ty

sand lilyBOT
rapid echo
#

am i not doing this right

heady karma
#

Hi @rapid echo I'm taking over this thread.

rapid echo
#

ok thank you

heady karma
#

Can you print out customer.shipping and see if it is None?

rapid echo
#

it gave me none

heady karma
#

OK, that explains the error then

#

Have you set a shipping to this customer?

rapid echo
#

it should be going thru all of them and exporting the objects to a csv

heady karma
#

Do you have the customer ID so I can take a look?

rapid echo
#

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

heady karma
#

That's possible, can you print out the customer ID so we can check?

rapid echo
#

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

heady karma
#

Do a null check?

rapid echo
#

im not sure ik what u mean

heady karma
#

Something like

if customer.shipping is not None: 
    address = customer.shipping.address.
rapid echo
#

can i get it to ignore it entirely

#

if customer.shipping is not None:
address = none

#

can i do that

heady karma
#

It's up to you

rapid echo
#

would that work

heady karma
#
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

rapid echo
#

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

heady karma
#

No, this discord thread isn't integrated to ticket system.

rapid echo
#

gotcha