How to send HTTP URL parameters in postman? - postman

How to send HTTP URL parameters in Postman?
Url: https://md.world.paas:443/data
URL parameters: key = ObjectList
How can I send URL parameters?

You can do it in the following ways:
Use environment variables:
click on the wheel top right
click on Manage Environments
either create an environment or click on Globals
define key-value pairs
you can use the values you defined by enclosing the key in double curly brackets/braces, as you see in the image.
Use local variables:
write the variable name in the url with a ':' in front of it, as you see in the image
click on the Params button at the right of the url
fill in the value for your variable
Use request parameters:
click on the Params button at the right of the url
fill in both key and value
a request parameters string will be appended to your url in the form of
?key1=value1&key2=value2

Related

How to use URL Pattern in chrome.cookies.get url field?

When I use a URL Pattern in the url field of chrome.cookies.get, I am not able to retrieve a cookie. When I type in a full URL, I am able to get the cookie. Is it not possible to use a url pattern in the url field of chrome.cookies.get?
Basically, I am trying to show a certain div when the user first logs into the site, but only the first time. I figured I can achieve this by checking the session, and it looks like the JWT token changes on each new session.
I tried this:
chrome.cookies.get({url: '*://www.mysite.com/*', name: 'JWT'}, function (cookie) {...} but it doesn't seem to work.
Do I need to use a full path? On https://developer.chrome.com/extensions/cookies#method-getAll it says
The URL with which the cookie to retrieve is associated. This
argument may be a full URL, in which case any data following the URL
path (e.g. the query string) is simply ignored. If host permissions
for this URL are not specified in the manifest file, the API call will
fail.
The 'may be a full URL' part makes me believe that you should be able to use a pattern in the URL field.
In my manifest file, I have
"webRequest",
"activeTab",
"storage",
"alarms",
"tabs",
"cookies",
"webNavigation",
"pageCapture",
"desktopCapture",
"tabCapture",
"http://*/*",
"https://*/*"
],
"https://*/*" should be able to match *://www.mysite.com/*.
Again, when I put the full url into the url field, I am able to get the cookie.

Postman and setting up a variable in the body of x-www-form-urlencoded request

So I'm trying to use chained request with Postman, where the first request will pass the data to the next request and I would use that data as a body. I was able to that, however there is an issue if there is x-www-form-urlencoded type of request involved because Postman will convert this:
Request body:
{{data}}
Into this:
{{data}: ""
Is there maybe a way to tell Postman not to add a colon in case variable is set as a body ?
Turns out there is no direct solution for this issue, so I had to find a way around. What I did was, create environment variables and then hard code key names and values that are expected in the request body:
Step1: Request1 - (Tests tab)
function setEnvironmentVars(obj) {
for(var prop in obj) {
postman.setEnvironmentVariable(prop, obj[prop]);
}
}
setEnvironmentVars(data);
postman.setNextRequest("Request2");
So instead of passing the data object to Request2, I am creating env variable for each property in the data object, which will be accessible directly. This is executed automatically after the Request 1 completes.
Step2: Request2 (Body tab)
In the Request 2, I set the request type to x-www-form-urlencoded and then bulk edited the body with keys and env vars as values:
VAR1:{{VAR1}}
VAR2:{{VAR2}}
This solution for works very well, as the key names are always the same.

Pass dynamic value to url in Postman

I have 2 requests
1st Request
After did my first request, I get the response where I can parse for a taskId
In my test tab, I will then parse and store it like this
let taskId = pm.response.json().body.result[0].data.task
console.log(taskId)
I can see taskId printing in my console as 938
2nd Request
I require making a GET with this dynamic URL with the taskId that I got from the first one
http://localhost:3000/fortinet/monitor/{{taskId}}
So I set the above URL , set the HTTP verb to GET
in my Pre-request Script tab, I did this
let taskId = pm.globals.get("taskId")
Result
ReferenceError: taskId is not defined
Image Result
How can I debug this further?
The most suggested way is to use :key as in
http://localhost:3000/fortinet/monitor/:taskId
See the colon before taskId. The reason being, URI values sometimes many not be environment dependent. So, based on the usecase, you can use like I said or {{taskId}}
You have to set variable, but you are doing it wrong.
try this:
pm.globals.set("taskID", pm.response.json().body.result[0].data.task)
more you can read here:
https://learning.postman.com/docs/postman/variables-and-environments/variables/
Please note, that URL which ends with resource identified like https://example.com/:pathVariable.xml or https://example.com/:pathVariable.json will not work.
You can go with https://example.com/:pathVariable with Accept: application/json header.
For passing dynamic value, first you have to set it in environment or global variable in Tests tab because tests runs after request and you will get response value after request sent, but because you get response in json you have to first parse it, so what you can write in Tests tab is as follows:
var jsonData = JSON.parse(responseBody);
postman.setEnvironmentVariable("taskId", jsonData.token); // OR
postman.setGlobalVariable("taskId", jsonData.token);
Then you can use taskId as {{taskId}} wherever you want in url parameters or in request body or form data wherever.
If you want to know in detail how to extract data from response and chain it to request then you can go to this postman's official blog post which is written by Abhinav Asthana CEO and Co Founder of Postman Company.

How to make post request with params and body in Postman

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.

Postman: Is it possible to update url of postman request in the pre-requisite script

Is it possible to update url of postman request in the pre-requisite script.
I want to edit the url based on dynamic environment input.
For example:
if (environment.someValue) {
request.url = request.url + "\" + environment.someValue
if (environment.anotherValue) {
request.url = request.url + "\" + environment.anotherValue
}
}
console.log(request.url);
The above code gives me prefect console log:
e.g. if url is https://someServer/someRequest, environment.someVar is x and environment.anotherVar is y the console.log(request.url) above prints:
https://someServer/someRequest/x/y
But the problem is (say if i am requesting a Get), even after logging the overridden request url, it only calls https://someServer/someRequest and does not override to https://someServer/someRequest/x/y.
Any ideas how to modify the url as asked above.
if your url in your request is set as a global, it should work.
ie. I have a get request :
GET http://{{myurl}}/etc. with myurl set as a global variable
In my prerequest script I do pm.globals.set("myurl", <new url>);
when I launch my request, it tries to do the GET request on my new url.
So it is possible to do it but you have to use global or environment variables to dynamically update your request:
set your 'someRequest' as a global that you can update in your prescript (instead of request.url), then it will be interpreted when you launch your request
https://someServer/{{someRequest}}
pm.request.url= "dynamic value"
you and update url using the above single line in postman prerequisite step
pm.request.url returns a object with fields host,path and params . But you can replace it with string.
Thanks for the tips: I used these lines of code to manipulate two values that appear in a RESTful API route:
// Ensure Payroll ID and Employee ID in request URL are correctly padded with zeros
pm.request.url.path[pm.request.url.path.indexOf("{{PayrollID}}")] = data.PayrollID.toString().padStart(6, '0');
pm.request.url.path[pm.request.url.path.indexOf("{{EmployeeID}}")] = data.EmployeeID.toString().padStart(7, '0');