-3

We are trying to query the Stripe API using Python3.7. According to documentation here, the syntax is this.

import stripe
stripe.api_key = "sk_test_GsmQDvulES2VzWpDTGF5rNHj"

stripe.Customer.search(query="email:'sally@rocketrides.io'")

In our codebase we have a variable that holds the value of the email address. We have tried the following, but they all result in error. The variable is "email_id"

 customer_object = stripe.Customer.search(query="email:'email_id'")
 customer_object = stripe.Customer.search(query="email: \''  email_id \''")

 customer_object = stripe.Customer.search(query= {
      "email:   email_id 
 })
        

Can you please suggest the right syntax? Thanks.

JonSG
  • 10,542
  • 2
  • 25
  • 36
Jack tileman
  • 813
  • 2
  • 11
  • 26
  • 2
    Please tell me that's not your actual API key... – Jared Smith Aug 03 '23 at 15:49
  • 1
    Are you asking how to format a string? `f"email:'{email_id}'"`? – Brian61354270 Aug 03 '23 at 15:50
  • @Brian61354270 I don't think so, that appears to be a literal copy pasta of the example code and if you follow the link there's no variable interpolation going on in it. My guess is OP has wrong version of the stripe API installed (relative to the docs they're referencing). – Jared Smith Aug 03 '23 at 15:51
  • 2
    @JaredSmith The first snippet is a copy-paste of the docs. The second is one where they're trying to provide the email address from a variable instead of hard-coding it. They're getting a syntax error because they're guessing how to insert a value from a variable into a string. At least that's my reading – Brian61354270 Aug 03 '23 at 15:54
  • @Brian61354270 you're right – Jared Smith Aug 03 '23 at 16:33
  • @JaredSmith - No cause for alarm bells. These are not actual API key. As stated in my question the syntax is from Stripe documentation. – Jack tileman Aug 04 '23 at 18:29
  • @Brian61354270 - thanks for the suggestion. What worked for me is the following syntax stripe.Customer.search(query = "email: " + "'" + email_id + "'" ) – Jack tileman Aug 04 '23 at 18:30

0 Answers0