Asad Ali Asad Ali - 19 days ago 5
reST (reStructuredText) Question

How to post some parameter in URL and some parameters as json value in postman

I have a post method as follows

@RequestMapping(value = "/user/profile", method = RequestMethod.POST)
@ResponseBody
public ResponseEntity<?> updateProfile(@RequestParam("userId") long userId,
@RequestParam(value = "profilePicId", required = false) Long profilePicId,
@RequestParam("payload") String payload) throws IOException {
//some logic
}


I want to hit it through postman, here is my request URL
{{host}}/abc/api/someVersion/user/profile/?userId=12345

where userId is request parameter, and json as another parameter(i.e., payload)

{
"showInitials": true,
"personalQuote": "",
"wooAlbum": [{
"photoStatus": "APPROVED",
"objectId": "1509974142644942",
"imageOrder": 0,
"srcBig": "http:\/\/amazonaws.com\/uploadedPhoto\/1472267515843.jpeg",
"profilePic": true
}, {
"photoStatus": "APPROVED",
"objectId": "1509970579311965",
"imageOrder": 1,
"srcBig": "http:\/\/amazonaws.com\/wooPictures\/1234.jpg",
"profilePic": false
}],
"degree": [{
"isSelected": 1,
"tagId": 1,
"tagsDtoType": "NONE",
"name": "No Info (update your linked account)"
}],
"company": [{
"isSelected": 0,
"tagId": 1,
"tagsDtoType": "NONE",
"name": "No Info (update your linked account)"
}],
"college": [{
"isSelected": 1,
"tagId": 169421983068086,
"tagsDtoType": "USER_EDUCATION",
"name": "MDU, Rohtak"
}],
"religion": [],
"location": " Delhi",
"showHeightType": "INCHES",
"ethnicity": [],
"isMutualFriendVisible": false,
"tagsDtos": [{
"tagId": "12",
"name": "Tennis",
"tagsDtoType": "WOO_TAG"
}, {
"tagId": "16",
"name": "Marathons Runner",
"tagsDtoType": "WOO_TAG"
}, {
"tagId": "19",
"name": "Basket ball",
"tagsDtoType": "WOO_TAG"
}],
"designation": [{
"isSelected": 0,
"tagId": 1,
"tagsDtoType": "NONE",
"name": "No Info (update your linked account)"
}]}


I posted it(json) under raw section of body, while format is application/json. also entered content-type and charset values under header section.

After hitting on send button ,i am getting 400(Bad Request) as response.

Could anyone suggest how to create url for these parameters?

Answer

Since the parameter type is @RequestParam, hence i passed payload with url (not in body) and it worked. here is the complete request URL

{{host}}/abc/api/someVersion/user/profile/?userId=12345&payload={"showInitials":true,"personalQuote":"abc","wooAlbum":[{"photoStatus":"APPROVED","objectId":"1509974142644942","imageOrder":0,"srcBig":"http:\/\/u2-woostore.s3.amazonaws.com\/uploadedPhoto\/1472267517964_4193248.1472267515843.jpeg","profilePic":true},{"photoStatus":"APPROVED","objectId":"1509970579311965","imageOrder":1,"srcBig":"http:\/\/u2-woostore.s3.amazonaws.com\/wooPictures\/1509970579311965.jpg","profilePic":false}],"degree":[{"isSelected":1,"tagId":1,"tagsDtoType":"NONE","name":"No Info (update your linked account)"}],"company":[{"isSelected":0,"tagId":1,"tagsDtoType":"NONE","name":"No Info (update your linked account)"}],"college":[{"isSelected":1,"tagId":169421983068086,"tagsDtoType":"USER_EDUCATION","name":"MDU, Rohtak"}],"religion":[],"location":" Delhi","showHeightType":"INCHES","ethnicity":[],"isMutualFriendVisible":false,"tagsDtos":[{"tagId":"12","name":"Tennis","tagsDtoType":"WOO_TAG"},{"tagId":"16","name":"Marathons Runner","tagsDtoType":"WOO_TAG"},{"tagId":"19","name":"Basket ball","tagsDtoType":"WOO_TAG"}],"designation":[{"isSelected":0,"tagId":1,"tagsDtoType":"NONE","name":"No Info (update your linked account)"}]}

Passed the complete valid json in url as parameter. It worked in my case.