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 ?
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.
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
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]
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"
}
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
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"}
}
Related
Is there any option to send mock results depends on form data body value in postman?
I am sending some value in the body as form data and I have two example result and now the mock API return only one example I need to get the result based on the form data value from two examples
I have to call 2 Request with different body values(as form-data) and I need to return json array if the values are correct else I need to return a json object I have saved this two result but while I making mock API it is all ways sending now result only there is no changes in url
Is that possible to send response based on form-data in postman mock api?
I have an api example https://api.exmple.com and i am sending post request wit body form-data and filed check:false or check:true and i need to respond two json based on input filed check false or true how to do it?
When we do with get parameter it is working but not working with body form-data
Updates
I added this in header x-mock-match-request-body:true
Post man responding with this error message
{
"error": {
"name": "mockRequestNotFoundError",
"message": "Double check your method and the request path and try again.",
"header": "No matching requests"
}
}
Update I added postman api key but is not working but when i add x-mock-response-name it is working but i need to x-mock-match-request-body only
I am trying send an image from POSTMAN. I am able to send a message but image is not getting posted.
https://slack.com/api/chat.postMessage
Used POST type headers i am passing token, channel and i have an Image URL but not sure how to send that. Can anyone please help me on this.
There are two alternative approaches on how to send your message to the API endpoint chat.postMessage:
Body as form-urlencoded
Here is how to include an image in a message send as x-www-form-urlencoded:
The image has to be send as part of an attachment by setting the property called image_url.
The attachments are set with the attachments key in the API call, which requires you define your attachments as array of attachment object in JSON.
In addition to the image_url your attachment needs to contain a fallback property, which is used to display a text to the user in case the image can not be displayed.
Your attachments object then looks like this in JSON:
{
"fallback": "this did not work",
"image_url": "https://secure.gravatar.com/avatar/d6ada88a40de8504c6b6068db88266ad.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F27b6e%2Fimg%2Favatars%2Fsmiley_blobs%2Fava_0016-512.png"
}
Now you have to put that into an array (by adding [] around it) and this is what you get as value for your attachments key:
[{"fallback":"did not work","image_url":"https://secure.gravatar.com/avatar/d6ada88a40de8504c6b6068db88266ad.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F27b6e%2Fimg%2Favatars%2Fsmiley_blobs%2Fava_0016-512.png"}]
In addition you need to add the keys token, channel, text key to your message. Voila.
Body as JSON
An alternative and probably easier approach is to send your data as JSON instead of x-www-form-urlencoded to the API.
This requires you to send the token in the Auth header and switch to JSON for the body.
To do that in Postman put your token as "Bearer Token" under "Authorization".
In "Body" switch to "raw" and select "JSON".
Then you can define the whole message as follows:
{
"channel": "test",
"text": "Hi there!",
"attachments":
[
{
"fallback": "this did not work",
"image_url": "https://secure.gravatar.com/avatar/d6ada88a40de8504c6b6068db88266ad.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F27b6e%2Fimg%2Favatars%2Fsmiley_blobs%2Fava_0016-512.png"
}
]
}
Of course you can do the same in your code. Since your are working in JavaScript using JSON would be the natural approach.
Note that not all API methods support sending the body in JSON. Check out this documentation for more info.
I have endpoint which takes few parameters and body as input, and I want to test it in Postman. But, when I input data into 'form-data' section in Postman backend throws error that I am missing body. If I try input data into 'raw' (Text) it complains that I forgot about parameters. How can I combine params and body?
EDIT:
'form-data' section
'raw' section
Parameters for that endpoint are following:
#RequestParam("to") String to,
#RequestParam("subject") String subject,
#RequestBody String content,
#RequestParam("isMultipart") Boolean isMultipart,
#RequestParam("isHtml") Boolean isHtml
For the request params you would add them to the end of the URL rather than in the request body, like you have done in the image.
?to=random#email.com&subject=Testing mailing feature&isMultipart=false&isHTML=true
This can be seen in the Postman UI when you select the Params button, this can be found next to the Send button.
I'm unsure about the string that you need in the request body and in what format the endpoint requires this data.
If it's in a JSON format you could add {"content": "Some new content"} to the raw body and select JSON (application/json) from the dropdown, this will also set the correct request header.
Edit:
The UI has changed slightly since this answer was given. The Paramstab is now placed in a less confusing place.
I've been googling for a few hours, and I need help. I dont think I'm using the correct words. Anyhow, I'm using Claudia.JS to set up a POST request to my AWS Lambda function. Here's the basics of the function:
api.post('/leads', function (request) {
console.log(request);
return request;
});
When I use postman to test the post request, I'm returned the request object. Awesome. Then I try to pass form-data through. I set the key to 'username' and the value to 'this is the username'. This is what request.body is:
"body": "---------------------------
-019178618034620042564575\r\nContent-Disposition: form-data;
name=\"username\"\r\n\r\nthis is the username\r\n----------------------
------019178618034620042564575--\r\n",`
I thought I could return request.body.username... to key the value of username...but I'm missing something.
How do I access the form data in the request?
update: okay. The website is taking the form data, making a post request...this function is receiving the post request? still-- in postman...if I were to put my own JSON in...why can I not access request.body like... request.body.username?
You should try console.log(request.data) to see your request object, ie. in my own case I can see the content of my request's body.
Have a look at https://www.getpostman.com/docs/postman/scripts/postman_sandbox to see all the relevant information about your request.
I solved this by looking at the header set in postman. It was set to form-data instead of application/JSON. All gravy now.
I found that when I use the collection.create to create a new model, backbone will send a post request, but the post data is incorrect
for example
collection.create({name:'test'})
backbone will send POST data using "{name:'test'}" as key, and "" as value,
but I want the POST data by using name as key, 'test' as value,
can anybody no how to setting it,
I use django as the server
thanks in advance
Unless you change it backbone's collections use Backbone.sync to communicate with your backend.
In the docs they say:
With the default implementation, when Backbone.sync sends up a
request to save a model, its attributes will be passed, serialized as
JSON, and sent in the HTTP body with content-type application/json
So I guess you need to do something like this in your django view
json.load(request.POST)
or use a custom sync function that does not serialize the data to json
You'll need to parse the raw post data string and parse it into a python dict.
import json
data = json.loads(request.raw_post_data)
You can also set
Backbone.emulateJSON = true;
as per http://backbonejs.org/#Sync-emulateJSON