Geek_To_Learn
Geek_To_Learn

Reputation: 1956

How to send a parameter which is dictionary in Postman

I have just started using Postman for testing my API. I am able to send list of request parameters, but could not figure out how will I send a parameter which is a dictionary,

say my request has two different parameters, first is property, and the structure of property is something like "ptype":"residential","mtype":"requirement","dtype":"sale","category":"multistoryapt","city":"Gurgaon,Mumbai"

How can I send these parameters together ? I have explored on internet and there are ways of sending an array but not a dictionary.

Am I missing something ?

Upvotes: 15

Views: 37972

Answers (7)

Jason
Jason

Reputation: 2915

I was faced with a similar problem with yours and solved it by using the form-data input type of POSTMAN. I have the following GET mapping for my Java spring RestController:

@GetMapping("/card")
    public ResponseEntity<CollectionModel<EntityModel<CardDto>>> aggregateGetCards(
            @RequestParam Map<String, String> filterParams,
            @RequestParam(name = "page", defaultValue = DEFAULT_PAGE_IDX) @Min(0) Integer page,
            @RequestParam(name = "items_in_page", defaultValue = DEFAULT_PAGE_SIZE) @Min(1)
            Integer pageSize,
            @RequestParam(name = "sort_by_field", defaultValue = DEFAULT_SORT_BY_FIELD) @NonNull @NotBlank
            String sortByField,
            @RequestParam(name = "sort_order", defaultValue = DEFAULT_SORT_ORDER) @NonNull
            SortOrder sortOrder
            ){
.
.
.
}

filterParams is a Map (the Java equivalent of a dictionary) that in JSON format would look something like:

{
     "name" : "[email protected]",
     "color" : "#FH90J7"
     "creatingUser" : "[email protected]"
     .
     .
     .
}

I can pass the pagination parameters ("page", "items_in_page", etc.) just fine from the Params tab of POSTMAN:

The Params tab of my POSTMAN

While for the filterParams Map, I have to use the form-data tab, for example:

The "form data" tab of my POSTMAN.

You might want to be a bit more consistent with snake_casing and camelCasing than I have been :)

Upvotes: 0

Abhi
Abhi

Reputation: 11

  • Match the name of your dictionary and Request body dictionary name.

Suppose ,

 Dictionary<string,string> randomName = new Dictionary<string,string(){{"key1","value1"} ,{"key2","value2"}};

so , your request for PostMan should be:

{
    "randomName " : { "key1":"value1", "key2":"value2"}
}

Upvotes: 1

Maximiliano Ces&#225;n
Maximiliano Ces&#225;n

Reputation: 170

You can do it with this:

POST Request in Postman:

Content-Type: Json/Application

{
   "IsManual":true,
   "platform":"IOS",
   "barcodeList":{"1":"DSSDsdsdsas","2":"DSSDsdsdsas"},
   "Client":"Cliente1",
   "ScanDate":"2018-10-16T17:03:02.2347052-03:00"
}

Upvotes: 3

MarcelH
MarcelH

Reputation: 39

I cam across this topic as I have a parameter

public Dictionary<string, string> Customer { get; set; }

for my REST API and I wanted to test it with Postman. Unfortunately I didn't find any quick help for how to send a Dictionary using Postman. After trying around some combinations this is what worked for me

Customer[0].Key:name
Customer[0].Value:Testname

Upvotes: 3

Simon
Simon

Reputation: 2733

If for some reason you cannot send it with json, here is how we send dictionaries in the form:

object[ptype], object[mtype], object[dtype], object[category], object[city]

Upvotes: 5

tonycdp
tonycdp

Reputation: 329

If you want to send it in the application/json format then the body should look like this:

{
    "key1":"value1",
    "key2":"value2"
}

For a comprehensive resource on how to serialise JSON go to http://www.newtonsoft.com/json/help/html/SerializingCollections.htm

Upvotes: 6

Andre
Andre

Reputation: 1238

You could send data as raw body with the Content-Type application/json, this way it's up to you how the data is structured.

Upvotes: 10

Related Questions