1

it is my first post here, so please forgive me if I did something wrong.

So, I need to do a POST request in NodeJS. I choose request-promise for it. Everything was working like a charm until I needed to use square brackets in a key name. So I have the following code:

var options = {
    method: 'POST',
    uri: 'https://link.com',
    form: {
        ecomTeam[]: 'value',
        ecomTeam%5B%5D: 'value', // tried this, doesn't work
        'ecomTeam[]': 'value', // tried this, doesn't work
        `ecomTeam[]`: 'value', // tried this, doesn't work
    }
  };

rp(options)
  .then ...

How do I get it to work? I have tried a few solutions as seen in the snippet above - with no luck.

1 Answers1

0

You can use brackets in an object key

var options = {
    method: 'POST',
    uri: 'https://link.com',
    form: {
        'ecomTeam[]': 'value',
        'ecomTeam[]1': 'value1'
    }
  }
  
  console.log(options.form['ecomTeam[]'])
  console.log(options.form['ecomTeam[]1'])
  

like this

mohammad javad ahmadi
  • 2,031
  • 1
  • 10
  • 27