183

I am using ASP.NET Web API: http://xyzdomain.com:16845/api/returns/returns

How do I send a POST request to the endpoint using Postman Chrome extension, given Items is a collection:

[
  {
    "Items": [
      {
        "sku": "9257",
        "Price": "100",
        "Quantity": "500",
        "DiscountPercent": "1",
        "backordered": "2"
      }
    ],
    "order_id": "F429768865001",
    "status_code": "Shelf",
    "Exception": "no error"
  }
]
n-verbitsky
  • 552
  • 2
  • 9
  • 20
user3965303
  • 1,831
  • 2
  • 12
  • 5

16 Answers16

192

Send it as raw data and set the type to application/json

enter image description here

broc.seib
  • 21,643
  • 8
  • 63
  • 62
standup75
  • 4,734
  • 6
  • 28
  • 49
  • 4
    what is actually happening when this data is sent as raw? Where and how is it stored in the request? – Anthony To Apr 15 '15 at 21:26
  • I'd use a web proxy to look at that if your curious (for example: fiddler on Windows, charles proxy on mac) – standup75 Jun 01 '15 at 19:55
  • 4
    How Do I add an image file in the raw JSON request? – Shikhar varshney Sep 01 '15 at 08:19
  • Yeah how do we add/upload image with raw JSON request. @Shikharvarshney Did you find a better way ? – Shahabaz Mar 19 '19 at 16:55
  • A life saver ... Thank you!! Working with Ruby on Rails, the prior code had nested ActionController::Parameters, within parent ActionController::Parameters. It took me a few hours, to figure out, that in Postman, it's: Body > Raw > JSON, not JSON within the Params. – Martin Sommer Aug 27 '21 at 16:30
165

To post a nested object with the key-value interface you can use a similar method to sending arrays. Pass an object key in square brackets after the object index.

Passing a nested item with Postman

"Items": [
      {
        "sku": "9257",
        "Price": "100"
      }
 ]
Kim Stacks
  • 10,202
  • 35
  • 151
  • 282
Peyotle
  • 2,255
  • 1
  • 15
  • 16
  • 13
    This is the best answer in my humble opinion... The easiest and most managable. – AturSams Apr 13 '17 at 09:19
  • 3
    This is what I was looking for, just that I had to write Items[sku] instead of Items[0][sku] – grom Nov 08 '17 at 12:17
  • 11
    In my case, I had a nested object called location with city, state and country in it. I had to write location.city, location.state, etc. – Aafreen Sheikh Nov 16 '17 at 05:32
  • 1
    Does this still work ? I do not think it does, Postman ends up making the entire "Items[0][SKU]" as a string – Amartya Gaur Apr 15 '22 at 08:15
35

This is a combination of the above, because I had to read several posts to understand.

  1. In the Headers, add the following key-values:
    1. Content-Type to application/json
    2. and Accept to application/json

enter image description here

  1. In the Body:
    1. change the type to "raw"
    2. confirm "JSON (application/json)" is the text type
    3. put the nested property there: { "Obj1" : { "key1" : "val1" } }

enter image description here

Hope this helps!

WasiF
  • 26,101
  • 16
  • 120
  • 128
TBirkulosis
  • 581
  • 5
  • 8
33

I got it working using the Raw data option in postman, as you can see in the screen shot

enter image description here

Mani
  • 2,391
  • 5
  • 37
  • 81
  • 7
    where exactly is this handling the nested data scenario? that's just the non-nested data which is being sent – Masroor Nov 15 '20 at 20:23
26

The key-value pair can take advanced inputs.

Ex.

enter image description here

aefhm
  • 541
  • 1
  • 5
  • 12
  • 1
    Thanks a ton man, I figured this would be there but I was trying dot annotation. This is certainly the correct answer – Jack Franzen Jun 26 '15 at 05:28
23

Simply add these parameters : In the header option of the request, add Content-Type:application/json

header content-type postman json

and in the body, select Raw format and put your json params like {'guid':'61791957-81A3-4264-8F32-49BCFB4544D8'}

json request postman

I've found the solution on http://www.iminfo.in/post/post-json-postman-rest-client-chrome

Ema.H
  • 2,862
  • 3
  • 28
  • 41
17

Select the body tab and select application/json in the Content-Type drop-down and add a body like this:

{
  "Username":"ABC",
  "Password":"ABC"
}

enter image description here

entpnerd
  • 10,049
  • 8
  • 47
  • 68
10

Just wanted to add one more problem that some people might find on top of all the other answers. Sending JSON object using RAW data and setting the type to application/json is what is to be done as has been mentioned above.

Even though I had done so, I got error in the POSTMAN request, it was because I accidentally forgot to create a default constructor for both child class.

Say if I had to send a JSON of format:

{
 "firstname" : "John",
 "lastname" : "Doe",
 "book":{
   "name":"Some Book",
   "price":12.2
  }
}

Then just make sure you create a default constructor for Book class.

I know this is a simple and uncommon error, but did certainly help me.

Toby Speight
  • 27,591
  • 48
  • 66
  • 103
bhanushrestha
  • 101
  • 1
  • 4
6

Best way to do that:

  1. In the Headers, add the following key-values:

    Content-Type to applications/json
    Accept to applications/json
    
  2. Under body, click raw and dropdown type to application/json

Also PFA for the same

enter image description here

enter image description here

Abhay
  • 6,410
  • 4
  • 26
  • 34
3

For a nested Json(example below), you can form a query using postman as shown below.

{
    "Items": {
        "sku": "10 Units",
        "Price": "20 Rs"
    },
    "Characteristics": {
        "color": "blue",
        "weight": "2 lb"
    }
}

enter image description here

Arpan
  • 913
  • 2
  • 12
  • 19
2

Just for those who want to send a nested JSON object with form-data as content type.

I want to send nested custom_field in below { "description": "Details about the issue...", "subject": "Support Needed...", "type": "Others", "email": "tom@outerspace.com", "priority": 1, "status": 2, **"custom_fields" : { "cf_type_of_issue" : "Complaint" }**, "cc_emails": ["ram@freshdesk.com","diana@freshdesk.com"] }

enter image description here

Muhammad Maqsood
  • 1,622
  • 19
  • 25
1

In the Params I have added model.Email and model.Password, work for me well. Thanks for the question. I tried the same thing in headers did not work. But it worked on Body with form-data and x-www-form-urlencoded.

Postman version 6.4.4

enter image description here

Kapila Perera
  • 837
  • 1
  • 11
  • 24
1

We can send nested JSON like the following format

address[city]
address[state]
n-verbitsky
  • 552
  • 2
  • 9
  • 20
0

If you want to send it as key-value Query Param via GET, you can paste your json in the inputtext as value, and then select this text, right click on it and click "EncodeUriComponent":

enter image description here

Vikcen
  • 153
  • 2
  • 9
0

If you want to post single nested dictionary lets say:

Wrong:

{

 parent_key: { child_key: child_value }

}

You need to convert it to:

Correct

{

 parent_key.child_key: child_value

}

And if you wanted to post list of dictionaries lets say:

Wrong:

{

 parent_key: [

    { child_key: child_value },
    { child_key: child_value_02 }
  ]

}

You need to convert it to:

Correct

{

 parent_key[0]child_key: child_value
 parent_key[1]child_key: child_value_02

}
Bermjly Team
  • 2,315
  • 3
  • 7
  • 16
0

When using Postman form-data, add nested obj or arr of nested objs in JSON.stringify format to the value field.

KEY = Items    VALUE = "{"sku": 9257, "Price":"100"}"

Then JSON.parse on the back end.

dimay
  • 2,768
  • 1
  • 13
  • 22
randall
  • 21
  • 2