Save example in Postman - postman

I want to save examples in postman. I know how to do that. But request is saved with variable placeholders if request contains any.
For example if request is something like:
{
id: {{someId}}
}}
In this example look the same way as request body - with variable place holder. Now I open console, open request body, copy and then paste in example's request. It is time consuming. Is there a way to force postman to save example with variable values?

Related

Postman path parameter following = in the request url

One of the requests for the tool I've been asked to update is the delete request which is structured as follows:
http://{{host_ip}}:{{port}}/lists/list_id=76218cb5fc45605cd632c26f5c5568ac/del
where the list ID will be different every time you send a request.
In order to simplify usage for end users, I want to be able to have them enter everything they need as parameters or headers in the postman GUI as they do for the other requests, rather than modifying the request URL, so I tried something like this:
http://{{host_ip}}:{{port}}/lists/list_id=:list_id/del
but if the : is preceded by an equals sign, the postman parameters tab no longer shows list_id as a path parameter.
Is there a way to make this work using a path parameter? Or is the best solution to explain to users that for the delete request, they need to paste the list_id obtained from the other requests into the request URL?
http://{{host_ip}}:{{port}}/lists/list_id={{list_id}}/del?list_id=1
Now users can pass the list id as query parameter.
In pre-request:
pm.environment.set("list_id",pm.request.url.getQueryString("list_id").split("=")[1])
pm.request.removeQueryParams("list_id")
this will update the list_id varaible and remove the query parameter and send the request in the format you want
If you want to achieve what you are saying then there is no solution for your problem.
But I would suggest you change your URL. As Divyang said, your URL should be like http://{{host_ip}}:{{port}}/lists/{{list_id}}/del or http://{{host_ip}}:{{port}}/lists/del?list_id=123 and then you can use params tab assign values to list_id.
But my best suggestion would be to use RESTful design: http://{{host_ip}}:{{port}}/lists/123123 and make a DELETE request to that URL.

What is the difference between Params and Body in Postman

This might be a really simple question but I can't seem to find a clear answer.
In postman, what is the difference between the Params and the Body tabs?. I noticed that when I was trying to perform a PUT request, if I am to add the key and value in Params my PUT request doesn't seem to update what I intend to update but if I perform the PUT request in Body and have the form-data selected than the expected update happens.
So what exactly are the differences?
Params correspond to the request parameters that are appended to the request URL.they are most used with GET requests. On the other hand, Body is the actual request body (usually it defines the request payload or the data that needs to be processed by the request). PUT and POST requests read usually the data from the body of the request and not from the params.

How to access the true RAW request body from post man on a pre-request script?

I'm trying to authenticate myself against an API. This API uses the raw body from the request to create the hash that it will use to authenticate against my token.
For testing purposes, I'm using postman with a pre request script to create the hash. Everything works fine, with one exception:
In the code tab I have this
however if on the pre request script I dump the value of the request body I get by using request.data I obtain
The problem is, its not exactly the same string, then the value retrieved by request.data creates a hash with a different body that the server uses to create its hash (the server uses the one beautified with line endings and tabs). This is the script where I use the request body content:
So unless someone have an idea of how to retrieve the json body exactly on the format it was written, pretty much seems I cant use postman for this
thanks!
EDIT: I don't know if this existed 5 years ago when the original Question was posted, but it's available in PostMan 8.12.2 at least.
When you have a request open in Postman, show the "Code" pane at the right by clicking the </> button seen in the right-hand toolbar.
Then in the dropdown header for code type, choose "HTTP".
The line numbers in the HTTP snippet are significant -- in my screenshot, the last four displayed lines are concatenated into line 6 of the actual HTTP.
just changed the post body tab to
new post body
and it went just fine. Not really the best solution i was expecting, but does the job :)

Trying To Insert Key/value Pairs To The Request Body With Postman

I am trying to insert key/value pairs to the request body in Postman, but I cannot do it! I click/double-click the body area, but nothing seems to happen.
I am stuck at this screen:
How can I add another JSON entry manually?
Looking at the screen shot, looks like you are trying to edit Response body rather than the Request body.
Postman only allows editing request body (which is logical).
If you want to use this response body contents in other request, copy and paste it in other request body and then edit it.

Save html page after JSON - AJAX post request

I use curl in C++ to download an html page from a website, then I save it.
After I've saved the html file, with another programm I've to read it, and save it in a string.
This page contain some request (POST) made by JSON-AJAX. If I open it with the broswer I have the right content. If I open it with a text editor I have a bad content because the POST request is not made.
So how can I save the page whit the content obtained after JSON-AJAX request??
Curl will download the HTML code from the page and that's it. When you open the HTML file with a web browser, the browser is taking care of whatever post request is being sent.
You need to find out what the post request contains (i.e., the data and how it's obtained) and send that request separately and save the response.
You might want to look into this question How do you make a HTTP request with C++?