Object in RESTapi query body (x-www-form-urlencoded)

Hi everyone,

I'm trying to send the below object to the Stripe api in my post request body.
Screenshot 2023-08-31 at 9.20.10 AM

Stripe gives me an invalid request error, saying that it's an invalid object.
Screenshot 2023-08-31 at 9.22.08 AM

With stringify, I get the same error, but a different body.

Any ideas what I'm doing wrong here?

Thanks in advance for your help!

Hi @casey_hemingway,

can you try putting it into strings?

{{ JSON.stringify({amount:1250, currency:'nzd'}) }}

The Stripe API seems to want this to be a HashMap or dictionary of <String, Object> types... not sure why the method of sending the object isn't working. My skills are limited in sourcing the options/differences between the data you are sending and how they expect it to arrive (even after poking around their API docs).

What it looks like they want you to do is get their client libraries and use that to make your requests. Unless there's a neat lodash function or something that generates <String, Object> hashes that aren't just read as [Object object] by the RESTapi making the request (which I'm sure there are, but I don't know them).

I even tried to make a code block map of the data to use but it seems like I'm doing something wrong since I don't get the mapped data returned out of the block:


Data in the above is a null Object. Probably a simple syntax thing I am unaware of for the data.

Hi @jocen and @pyrrho - using exactly that syntax, I get the third screenshot as a response. I'm assuming that I'm simply using the wrong character encoding or something like that, seeing as it prefaces each double quote with a back slash...

Must be something to do with the x-www-form-urlencoded API format.

Without stringify, this is my request body:
Screenshot 2023-09-05 at 8.40.22 AM

With stringify, it looks like this:
Screenshot 2023-09-05 at 8.44.49 AM

The second approach looks closer, as it actually send the object's data, but Stripe is still reading it as an invalid object. Likely as the result is not formatted as an object, given the double quotes around it and the myriad back slashes.
Screenshot 2023-09-05 at 8.47.57 AM

Any ideas about how I could manually concatenate the characters together to get the right object format?

Hey @casey_hemingway!

It looks like stripe docs include a specific syntax for how to pass objects, does something like this work for you?


@casey_hemingway Following up to confirm that this syntax is what the Stripe API is looking for. We were all very close but fighting against what the API expected: two key/value pairs instead of one object containing them.

1 Like