349

I've been using Postman Chrome extension to test out my API and would like to send an array of IDs via post. Is there a way to send something list this as a parameter in Postman?

{
  user_ids: ["1234", "5678"]
}
rsanchez
  • 14,467
  • 1
  • 35
  • 46
Will Hitchcock
  • 4,648
  • 3
  • 22
  • 32
  • 1
    I'm fairly certain the right way to send an array is "in some way that the *particular* server you are sending it to will receive it correctly". This accounts for the variation in answers below - but it'd all be a bit more useful if everyone (or anyone?) had said what back-end they were using. – mwardm Mar 02 '18 at 15:49

25 Answers25

619

You need to suffix your variable name with [] like this:

send_array_param_with_postman

If that doesn't work, try not putting indexes in brackets:

my_array[]  value1
my_array[]  value2

Note:

  • If you are using the postman packaged app, you can send an array by selecting raw / json (instead of form-data). Also, make sure to set Content-Type as application/json in Headers tab. Here is example for raw data {"user_ids": ["123" "233"]}, don't forget the quotes!

  • If you are using the postman REST client you have to use the method I described above because passing data as raw (json) won't work. There is a bug in the postman REST client (At least I get the bug when I use 0.8.4.6).

Muhammad Soliman
  • 21,644
  • 6
  • 109
  • 75
Benjamin Crouzier
  • 40,265
  • 44
  • 171
  • 236
  • 3
    Just in case someone is asking how to add hashes instead of just array, the idea is still the same, just change the indexes to hash name `my_array[hashname] value1` – Bryan P Jun 16 '14 at 02:48
  • 6
    `my_array[] value` will create a array parameter with the values provided, as `key => [value`]. `my_array[key] value` will create a hash, as `{key => value}`. – MARC.RS Aug 14 '15 at 13:10
  • 1
    none of them worked but I figured out just adding the array name works in 2019. [http://prntscr.com/nqubpi] – Shreyan Mehta May 20 '19 at 09:01
  • 1
    Your 2nd option without index, solved my issue, Thanks – shubham mishra Sep 03 '20 at 12:34
94

For me did not work with array[0], array1, .. or array[], array[], ... . It works more simply: enter image description here

Popa Andrei
  • 2,299
  • 21
  • 25
70

If you want an array of dicts, try this: enter image description here

C.K.
  • 4,348
  • 29
  • 43
  • 3
    For me what worked for node.js / mongoose is ```social_links[0].name``` notice the additional **period** – Songtham T. Nov 06 '18 at 04:37
  • In your example what if `name` is also an array? I tried something like `social_links[0]name[0]` in Django REST Framework (nested writable model-serializer with many-to-many relations) and it didn't work. – Nathan Feb 20 '20 at 04:14
  • As long as I add a '.' after the index (e.g. social_liks[0].name) this works for me from Postman using Spring Rest. – paiego Jul 29 '20 at 21:55
  • unfortunately, social_link[0].name doesn't work for me , when I check postman body request it shows "social_link[0].name" = "136" do you've any Idea why ? – Emad Jan 11 '21 at 10:57
  • how to create a custom request for for this in laravel 8 ? – Azade Nov 04 '21 at 05:52
  • For laravel, social_link[0][name] should work – Abdelkrim Laloui Feb 20 '23 at 10:25
60

Here is my solution:

use form-data and edit as below:

Key       Value 
box[]      a
box[n1]    b
box[n2][]  c
box[n2][]  d

and you will get an array like this:

{"box":{"0":"a","n1":"b","n2":["c","d"]}}
Gary
  • 1,199
  • 1
  • 9
  • 23
  • 1
    Great! finally I can send a object "loc": { "type": "Point", "coordinates": [ 126.972967, 37.54171 ], } to type in loc[type]: Point, loc[coordinates][] :126..., loc[coordinates][]: 37... on Postman thx!! – JillAndMe Sep 28 '18 at 14:03
  • This is very helpful as when you need to send files, the 'raw' format of Postman just won't work. You need to use the form-data format. – arunt Jun 18 '20 at 15:23
  • The only down drawback of this solution is that if you use number as a key, the blank one will be the last key. array[0], array[1], array[], the blank one will be array[2] – Trisno Raynaldy Nov 01 '22 at 08:32
39

It is important to know, that the VALUE box is only allowed to contain a numeral value (no specifiers).

If you want to send e.g. an array of "messages" with Postman, each having a list of key/value pairs, enter e.g. messages[][reason] into the KEY box and the value of reason into the VALUE box:

enter image description here

The server will receive:

{"messages"=>[{"reason"=>"scrolled", "tabid"=>"2"}, {"reason"=>"reload", "tabid"=>"1"}], "endpoint"=>{}}
Alexander Roehnisch
  • 675
  • 1
  • 7
  • 10
36

I also had that problem, and solved it by doing the following:

1 - Going to the request header configuration and added the following:

Accept : application/json, text/plain, */*
Content-Type : application/json;charset=UTF-8

2 - To send the json array, I went to raw json format and set the user_ids to array:

user_ids: ["bbbbbbbbbb","aaaaaaaaaa","987654321","123456789"]
devamaz
  • 95
  • 1
  • 8
mesteves
  • 408
  • 4
  • 8
28

Set Body as raw and form the array as follows:

enter image description here

danywarner
  • 928
  • 2
  • 15
  • 28
  • { "question" : "What is capital of India", "marks" : 1, "options" : [ "Mumbai", "Pune", "New Delhi", "Jaipur" ], "correct" : "New Delhi" } – Prathamesh More Mar 12 '20 at 11:07
24

As mentioned by @pinouchon you can pass it with the help of array index

my_array[0] value
my_array[1] value

In addition to this, to pass list of hashes, you can follow something like:

my_array[0][key1] value1

my_array[0][key2] value2

Example:

To pass param1=[{name:test_name, value:test_value}, {...}]

param1[0][name] test_name

param1[0][value] test_value
Abdulla Nilam
  • 36,589
  • 17
  • 64
  • 85
Manoj
  • 300
  • 2
  • 7
  • This worked for me. Since, i also needed to send image file in request, along with array of object this is what i needed. There is no way to send the image file in raw format(json) – iheathers May 15 '22 at 18:50
19

Go to Header and select Content-Type = application/json then go to body and select raw and then pass an array.enter image description here

Farhan
  • 1,445
  • 16
  • 24
17

this worked for me. to pass an array of Item object {ItemID,ColorID,SizeID,Quntity}

Postman data

Abdu Imam
  • 393
  • 3
  • 16
9

in headers set

content-type : application/x-www-form-urlencoded

In body select option

x-www-form-urlencoded

and insert data as json array

user_ids : ["1234", "5678"]
Aris
  • 4,643
  • 1
  • 41
  • 38
  • 1
    Only one that worked for me using form data! Couldn't use raw since I'm sending images too – Matt Wills Jan 21 '20 at 09:46
  • The only one worked for me as well For complete newbies: Press x-www-form-urlencoded => bulk edit => UserNames:["UserName1","UserName2", "UserName3"] – Denys Moroz Jan 21 '20 at 23:41
9

This also works for lists within the object:

Id:37
IdParent:26
Name:Poplet
Values[0].Id:1349
Values[0].Name:SomeName
Values[1].Id:1350
Values[1].Name:AnotherName

the equivalent JSON would be:

{
    "Id": 37,
    "IdParent": 26,
    "Name": "Poplet",
    "Values": [
        {
            "Id": 1349,
            "Name": "SomeName"
        },
        {
            "Id": 1350,
            "Name": "AnotherName"
        }
    ]
}
onicofago
  • 302
  • 5
  • 12
  • unfortunately, Values[0].Id doesn't work for me , when I check postman body request it shows "Values[0].Id" = "1349" do you've any Idea why ? – Emad Jan 11 '21 at 10:56
9
{
    "data" : [  
        {
            "key1" : "value1",
            "key2" : "value2"   
        },
        {
            "key01" : "value01",
            "key02" : "value02"             
        },
        {
            "key10" : "value10",
            "key20" : "value20"   
        }
    ]
}

You can pass like this.

Nimantha
  • 6,405
  • 6
  • 28
  • 69
Narendra Solanki
  • 1,042
  • 14
  • 20
9

In form-data you can pass a array like this

enter image description here

and in backend you will fetch it like a

"tags"=>["aaaa", "bbb"]

In my case I've to pass two values in a array so I write it two times

manish nautiyal
  • 2,556
  • 3
  • 27
  • 34
6

Choose either form-data or urlencoded and use the same key "user_ids". The server should receive it as an array.

Abhinav
  • 38,516
  • 9
  • 41
  • 49
  • Looks like, due to a bug in Chrome that erroneously sends with an XML header even when you select JSON in Postman, you have to add a `Content-type` header with value `application/json`. – Jason Swett Jul 01 '13 at 18:40
  • 6
    just in case someone comes back looking for an answer, the key for an array should be user_ids[] instead of just user_ids – anguyen May 18 '14 at 22:31
5

In form-data,

   key              value

 user_ids[]         1234
 user_ids[]         5678
Mritunjay Upadhyay
  • 1,004
  • 1
  • 15
  • 27
5

My back-end is written in Ruby on Rails. This is how I sent the array params using Postman. It worked for me.

UPDATE

I'm using x-www-form-urlencoded. I believe it will work too for form-data.

enter image description here

Zulhilmi Zainudin
  • 9,017
  • 12
  • 62
  • 98
3

Request header configuration and added the following

Accept: application/json

You need to suffix your key variable name with []

like key[0][name]

enter image description here

You can insert it in "bulk-edit" mode

Body section in form-data on right side click Bulk Edit and added the following

items[0][prod_id]:174336
items[0][item_weight]:3.400
items[0][item_qty]:1
items[0][item_selected_melting]:92
items[0][item_remarks]:
items[1][prod_id]:12345
Vishal Vaghasiya
  • 1,857
  • 2
  • 14
  • 21
2

In my case I need to send array of objects, I sent it like this enter image description here

Al Fahad
  • 2,378
  • 5
  • 28
  • 37
1

To send an array using form data there's no need to use brackets. Just send that specific array using the same name in multiple fields.

Like:

my_array:value_1
my_array:value_2
Yunnosch
  • 26,130
  • 9
  • 42
  • 54
Ali Nowrouzi
  • 59
  • 1
  • 5
  • 1
    Please double check your understanding of the difference of "answer" and "question". ;-) Harmless mistake of course. – Yunnosch Sep 03 '22 at 13:59
1

Although this question has already accepted a solution still that solution has a drawback that is we have to repeat the key (Array name) again and again as one key is accepting only one value. Like this:

Postman form-data (Key-Value Pairs)

Imagine we have 10 values or more, should we repeat the same Array name each time? The programmatic answer is NO. Then we should do the following that is a better approach.

  1. Select the form-data as usual
  2. Type Array name in the Key field
  3. Pass the Array in Value field

Like this:

Passing Array in Postman

Now, you should be able to send the Array, but wait, this won't be stored in Database like that in my case with MongoDB. So what you have to do is, use the following piece of code to send it like an Array in the Database:

  1. First, we need to parse it using JSON, like this

let user_ids = JSON.parse(body.user_ids);

  1. Now, you can send user_ids variable to database like an Array

That's All!

ARHAM RUMI
  • 441
  • 5
  • 11
0

I tried all solution here and in other posts, but nothing helped.

The only answer helped me:
Adding [FromBody] attribute before decleration of parameter in function signature:

[Route("MyFunc")]        
public string MyFunc([FromBody] string[] obj)
Rachel Fishbein
  • 818
  • 2
  • 12
  • 29
0

Supposing you have the array of object below,

features: [
      {
        title: { type: String },
        type: { type: String },
      },
    ],

To add the values on the form data on the postman, add it this way

features[title]
features[type]

Check also the image below

enter image description here

Sunday Aroh
  • 21
  • 1
  • 4
0

Here is something that worked for me

{
 "user_ids":["[1234, 5678]"]
}

I believe it depends on how the backend is setup most of the time.

Daniel Chettiar
  • 143
  • 1
  • 10
0

N.B Now we are in 2022 if All of the above solutions didn't, just don't panic. pass array name with is value without a bracket and the add it multiple time, just link how the image below is showing. it should work just fine. If It does work, buy me some coffee, hhh

enter image description here