When manually testing requests in Postman, is there a way to define some set of default headers to be used for each request (without choosing manually Preset before sending each request)?
I.e. is there a way to define a default Preset to be used?
Additionaly when I follow some of the links in the response (by clicking on it) and send a request for this link, the headers from the original request are lost. Is there a way to preserve them automatically?
Thanks in advance
There is no direct way to do this but this can be done via Collection level Pre-request script. Steps-
Create a collection in the postman and put all requests in which you want the common headers.
Edit the postman collection.
Write this in your Pre-request Script section.
var Header = require('postman-collection').Header;
pm.request.headers.add(new Header("foo:foo"))
pm.request.headers.add(new Header("bar:bar"))
As of 7.0.9 - You should be able to now do this in your Pre-request Scripts.
You can use the following syntax:
pm.request.headers.add({key: 'header_name', value: 'header_value' })
pm.request.headers.upsert({key: 'header_name', value: 'header_value' })
pm.request.headers.remove('header_name')
Tips: Fork this collection to see how it works directly in Postman:
https://www.postman.com/postman/workspace/postman-answers/collection/9215231-ef055751-7385-45b4-a6f9-91bbd1c47fa5?ctx=documentation
Related
In Insomnia test suite, is it possible to add or update the request body?
For example, I have get/post request in a collection which takes a json as request body, I like to test the request by changing this json. By default in test suite I can select a request and the defined json (under collections) is used for testing, what if I want to change this json request?
An example code is
const response1 = await insomnia.send();
expect(response1.status).to.equal(200);
Is it possible to change what is posted in insomnia.send() within the test suite? As of now I have to go to the collection change this json but what if I want to test the same api end point with different jsons?
I am aware, I can test it under collection (Debug tab) by changing the JSON and directly testing there but I am trying to leverage the test suite to write a bunch of test against an end point. Insomnia uses Mochajs for testing, is there any sample of that used long with insomnia?
I cannot find any pointers in Insomnia documentation.
I need to test the load and performance test of the API which is hosted in the AWS API gate way. Im using two post methods to get the final result. first post method will pass the below parameters in json format in the API.
{
propno:"xxxxx",
apikey:"xxxx-xxxx",
user:"xxx"
}
by executing this i will get a reference number and status of the execution
{
reference:"ABxxxxxxxxxna",
status:"ok"
}
Then will pass this reference no in another post method to get the desired result.
{
refno:"ABxxxxxxxxxna",
apikey:"xxxx-xxxx",
user:"xxx"
}
Now i want to perform the load test in Jmeter. Any help would be appreciated.
What is your question exactly?
In JMeter you can send a POST request using HTTP Request sampler, the relevant configuration would be something like:
the refno value can be fetched using JSON Extractor configured like:
next in the second HTTP Request use ${refno} reference to the JMeter Variable
You might also need to add a HTTP Header Manager and configure it to send the Content-Type header with the value of application/json
once done you can
Add more users in the Thread Group according to your NFR/SLA/common sense/whatever
Run your test in command-line non-GUI mode
Generate HTML Reporting Dashboard and analyze the results
I am creating a script on groovy to be able to send http requests.
To call this script I'm using the JSR223 Sampler
The thing is that I would like to reproduce as much as possible the behaviour that a HTTP Sampler has, meaning that I want to perform the request and also to fill the sampler's info (Response data, Request and Response)
Although I'm able to obtain SampleResult and set Response data and Response, does not seem to exist a method to set our own request string:
https://jmeter.apache.org/api/org/apache/jmeter/samplers/SampleResult.html
Following the docs, the closest method to do what I want is the setRequestHeaders().
If I call that method like this SampleResult.setRequestHeaders("My custom text") something like this appears on the request tab:
File C:\Users\UserName\groovy_file.groovy
Request Headers:
My custom text
Is there any way to print only the string My custom text, on the Request?
EDIT
Sampler must use a script file instead of the script field
The easiest way would be just overwriting the data using prev.samplerData() shorthand from the JSR223 PostProcessor
prev.samplerData = 'put the desired request data here'
where prev stands for the parent SampleResult class instance, check out Top 8 JMeter Java Classes You Should Be Using with Groovy article for more information on the JMeter API shorthands available for the JSR223 Test Elements.
If you don't want the PostProcessor you can still call the same function from your Groovy script like:
SamplerResult.setSamplerData('put the desired request data here')
I want to use Postman to test the REST API of a project, and I'm trying to a generic request. For example:
I have a POST request that makes a research, the parameters of this research
are in the body. How do I automate the request with a pre-request-script that modifies the body at each iteration?
Because I don't want to create a collection with 20 POST requests where only the body changes. I tried to use a while loop in pre-request-script or in test script but Postman executed the request only once. Then I tried to use the runner for calling the request 5 times, for example, and i wrote a script that modified a variable each time, but I think that global and environment variable are reset at each iteration of the runner.
Do you have any ideas?
enter image description here
I tried that to modify value of password when I use the runner. But if the runner reset variables at each iteration it can't work.
It's ok I found an other solution:
For example I want to test the request with 5 different password, i create 5 file json who correspond to my global variables or environment variables and in this files I modify just one variable. I use newman i a loop script to call the same request with different global variable file to modify just one parameter of the request.
You can also use set_nextRequest() (see http://blog.getpostman.com/2016/03/23/conditional-workflows-in-postman/). With this you should be able to force calling your request again with the new value for your password and not perform multiple iterations. If you use a global variable in your json body and you update it in your loop, it should work.
hope this helps
Alexandre
I need to update an order which is done via PUT method passing the order id as part of the https url string and a single parameter, the status_id.
https://mystore.mybigcommerce.com/orders/12345.json
I have tried several methods to pass the status_id value but no matter what I try "status_id=12" or formatted as JSON "{"status_id": 12,}" I always get the same response:
[{"status":415,"message":"The specified input content type is not valid."}]
I have also tried as a POST request passing the JSON or XML code as raw data but that method is not supported.
How am I supposed to pass that field=value pair? can I embed it in the url string?
I also tried it but it wouldn't work for me.
Any ideas?
In case you are wondering I am doing it within FileMaker with TROIUrl plugIn, not a very popular technology, but the GET method retrieving orders works like a charm
TURL_Put( ""; $url ;"status_id=12") (I have also tried other FM plugIns to no avail)
Don't get too caught up in the Filemaker part, I don't expect many people out there to be familiar with BigCommerce and Filemaker. I just need a generic answer.
Thanks
Commandline tool curl is worth a try. It supports put and https.
Mac OS X: curl already installed, call from FileMaker via AppleScript do shell script.
Windows: must be installed, call via Powershell.
It works for me using { "status_id": "3" } which means you probably need to put quotes around the actual number.
Also, it is a PUT operation and application/json which is part of the request content.
The error message received by the OP:
[{"status":415,"message":"The specified input content type is not valid."}]
Is saying that he did not supply the 'Content-Type' header in his request or that the header supplied is for a content type that is not allowed. For the OP's case using JSON he would need to include the header:
Content-Type: application/json
in his HTTPS request. This description can be found along with those of the other status codes you may see here:
https://developer.bigcommerce.com/api/status-codes