#jimin - Request Payloads

1 messages ยท Page 1 of 1 (latest)

static falcon
#

Also, I'm not sure what json.dumps is doing there... I'm not very familiar with Python or the requests library. Can you explain what that piece does?

somber sundial
#

Yeah we are using some api gateway proxy which makes it necessary for us to hit the API directly ๐Ÿ˜ฆ here is a link to what I am referring to:
https://stackoverflow.com/a/58436785

#

I'm not sure what our request id is

#

I get this error:

{'error': {'message': 'Invalid object',
           'param': 'card',
           'type': 'invalid_request_error'}}

for this endpoint
"https://api.stripe.com/v1/payment_methods"

static falcon
#

Can you get the response headers from that request?

#

The request ID should be in there.

somber sundial
#

aha here it is req_UmVagViUzeCRD1

static falcon
#

Thanks! Taking a look...

#

Ha, so, yeah, that's not going to work. Our API got a JSON string as the value of the card property.

#

This is the raw POST data we got in the body:

card=%7B%22exp_month%22%3A+3%2C+%22exp_year%22%3A+2023%2C+%22number%22%3A+%224242424242424242%22%2C+%22cvc%22%3A+%22314%22%7D&type=card

If you URL decode that it turns into this:

card={"exp_month":+3,+"exp_year":+2023,+"number":+"4242424242424242",+"cvc":+"314"}&type=card
somber sundial
#

ohh ok thank you! Do you have a recommended way of doing payloads with python? I know you recommend using stripe sdk but if you have seen others do it that might be helpful!!

static falcon
#

Not with Python, no. Hang on a moment though...

#

I found someone on my team who knows way more about Python than I do. ๐Ÿ™‚ Can you share the entire requests.post() code you're using?

somber sundial
#

This is what works

payment_method = {
  "card[exp_month]": 3,
  "card[exp_year]": 2023,
  "card[number]": "4242424242424242",
  "card[cvc]": "314",
  "type": "card"
}

response = requests.request("POST", url, data=payment_method, headers=headers)

but this is what I would hope would work

payment_method = {
  "card": {
    "exp_month": 3,
    "exp_year": 2023,
    "number": "4242424242424242",
    "cvc": "314"
  },
  "type": "card"
}

response = requests.request("POST", url, data=payment_method, headers=headers)
#

since parsing it to the above format kind of gets complicated with nested payloads

static falcon
#

Thanks!

somber sundial
#

perfect!! Thank you so much for your help!!