#nickh-nodejs-rawhttp

1 messages ยท Page 1 of 1 (latest)

graceful scarabBOT
dusk verge
#

Hey hey

#

So using JS fetch (Node JS) form Zapier

#

from*

cedar mauve
#

Not sure, I've never written code like this before. Doesn't Zapier support making Stripe API Requests direcrtly?

#

nickh-nodejs-rawhttp

dusk verge
#

it does as a BETA thing yes...

#

ironically,I thought raw might be more stable ๐Ÿ˜‰

#

anyway yeah body seems totally empty...

#

I checked the Stripe log

cedar mauve
#

yeah so it means you never passed the parameter properly in this case

dusk verge
#

hmmmm

#

`let data = new URLSearchParams();
data.append('type', 'express');

fetch('https://api.stripe.com/v1/accounts', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-type': 'application/x-www-form-urlencoded',
'Authorization': 'Basic ' + Buffer.from('sk_test_REDACT:').toString('base64')
},
body: data
}).then(function(res) {
return res.json();
}).then((json) => {
callback(null, json);
});`

#

not sure what could be wrong with that...

cedar mauve
#

why are you using URLSearchParams for something like this though?

dusk verge
#

what's the alternative?

#

(because Stripe API doesn't accept JSON? - it said I had to form-urlencoded)

#

um, apparently this is the alternative... eg::
var formBody = []; for (var property in details) { var encodedKey = encodeURIComponent(property); var encodedValue = encodeURIComponent(details[property]); formBody.push(encodedKey + "=" + encodedValue); } formBody = formBody.join("&");

then: body: formBody

#

would be nice if Stripe API accepted JSON like every other API out there ๐Ÿ˜‰

cedar mauve
#

sure

dusk verge
#

๐Ÿ™‚

#

OK - works using the other method

#

customer request - please make Stripe API accept JSON too ๐Ÿ˜‰

#

thanks for the help