#jimin - Request Payloads
1 messages ยท Page 1 of 1 (latest)
Hello! Can you give me the request IDs for both of these so I can take a look? Here's how you can find a request ID: https://support.stripe.com/questions/finding-the-id-for-an-api-request
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?
Also, we strongly recommend using our official Python library instead of hitting the API directly: https://github.com/stripe/stripe-python
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"
Can you get the response headers from that request?
The request ID should be in there.
aha here it is req_UmVagViUzeCRD1
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
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!!
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?
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
Thanks!
So the bad news is that you're going to get the parameters into the format in the first version. The good news is you can look at the way our Python library does it right here: https://github.com/stripe/stripe-python/blob/bc872674ba5c8ffd7d830f83ccb8e2adab53fd86/stripe/api_requestor.py#L28
perfect!! Thank you so much for your help!!