Reputation: 427
redirected: false
status: 400
statusText: "Bad Request"
type: "cors"
url: "https://api.stripe.com/v1/customers"
return this error.
let customer= {
"name": "xxxxxx",
"phone": "xxxxxxxxxx",
"email": "[email protected]",
"description": "test account "
}
let url = 'https://api.stripe.com/v1/customers';
let body = {
method: 'POST',
headers: {
'Content-Type': 'application/form-data',
'Authorization':'Bearer sk_test_xxxxxxxxxxxxxxxx',
'Stripe-Version': '2014-12-22',
},
//body: JSON.stringify(customer),
//json:true
body: customer
}
let response = await fetch(url, body);
console.log("response ",response.type)
if (response.ok) {
let json = await response.json();
} else {
console.log("err",response)
}
Upvotes: 1
Views: 454
Reputation: 6102
I've often found one of the fastest and most effective ways to debug problems with Stripe is by using the developer tools they provide, in particular the logs. For example, when I ran into this particular problem Stripe let me know that a parameter I was passing it (amount
in my case) had become null - once I fixed this, my "bad request" errors disappeared.
Stuff like this is why Stripe are known for their developer experience, so it makes sense to to take advantage of it wherever possible and minimise the time you spend losing sleep and hair over an issue.
Upvotes: 0
Reputation: 594
Stripe docs says the request was unacceptable - 400 bad request is often due to missing a required parameter, so check the API docs from here and check what is missing:
https://stripe.com/docs/api/customers/create
Upvotes: 1