JSON construction for POST request

I have a input box and button used to make a POST request.
The input field that takes in a list of order ids:


I need the order ids to be packed into JSON like so:
{'order_ids': [614522,617231]

How can I construct this JSON to send in a POST request?

Keep in mind, I am not using a traditional form. I just have:

  • an input field to accept the order ids
  • a button to send the POST request
  • a result field to show the retrieved data

Hey @mc1392,

Try creating a transformer like this:

let orderIds = {{textInput.value.split(',').map(x => parseInt(x))}}

return {
  order_ids: orderIds

and using the transformer.value in your post request.


I can see my POST params are are correct:

  1. bodyParams: {0: {order_ids: [617705, 617706]}, length: 1}

  2. 0: {order_ids: [617705, 617706]}

       1. order_ids: [619905, 617723]
         1. 0: 619905
         2. 1: 617723
     2. length: 1

@minijohn is there any way to enclose the key with quotes?

Also, I need the data to be sent as such:
{"order_ids": [123, 456]}

Currently, when I look at the Google Chrome console, I can see the key has no quotes around it.
Also, I think the structure is wrong:
1. bodyParams: {0: {order_ids: [617723]}, length: 1}

  1. 0: {order_ids: [617723]}

    1. order_ids: [617723]

I truly believe the structure is an issue. I don't want to change my API, I figure it should be easier to adjust the transform function.

      1. 0: 617723

Hey mc1392,

Great suggestion minijohn! Chiming in from support here. If you need the key to have quotes around it then you could use minijohn's suggested JS transformer function with quotes added to the key:

let orderIds = {{textInput.value.split(',').map(x => parseInt(x))}}

return {
"order_ids": orderIds

Do you think that could work you?