'Bulk POST/PUT API requests using POSTMAN or any other means
I have a list of API requests which are already in URL format. I just need to POST them one after the other automatically and log their results.
The only way I could do is to copy each url and send them using postman. But its really time consuming. I tried looking at task runner but that seemed hard to set the variable equal to the data file with all my requests
https://someApi/clientAssign?auth=123|asdf&otherParamsList=123Params
https://someApi/clientAssign?auth=123|asdf&otherParamsList=456Params
https://someApi/clientAssign?auth=123|asdf&otherParamsList=899Params
I am not sure of a way to fire the above urls one after the other using postman. I have around 60 POST requests and 60 PUT requests
Can anyone suggest a way to achieve this. I can do it by copying over the urls and manually posting them. I am just not in a position to spend so much time doing this very often. And I have already spent time preparing the url with proper values being substituted and ready to to go. Any help is appreciated.
Solution 1:[1]
Never mind I figured out a way to use postman's collection runner to accomplish the same. For those who struggled like the way I did, here is how to use that feature and its even easier to substitute values to your url on the go.
First create a request in Postman:
Below is a screenshot for Example:
Now the requirement is to post the below url: https://someApiPOSTRequest/clientAssign?auth=123|asdf&otherParamsList=123Params&someOtherParams={{VariableFromFile}}&additionalParams=hardcodedOnURL
with values being substituted for {{VariableFromFile}} from the csv file you will need to upload. Your csv should be formatted as below, where the header should have the same variable name used on your url:
Click on the '>' button shown below beside Example folder and click on 'Run' to open the same on Collection runner window of postman:
Once the Collection Runner window opens up, click on select file option to upload your csv file, and the Iterations field is pre-filled with the number of records on the csv file by default. You can change the number and when you do make sure of the number of iterations you want to run as its directly related to number of rows in your uploaded csv.
You can also preview your uploaded csv file:
If you click on Run Example button, the collection runner posts the url 9 times with {{VariableFromFile}} being substituted with value from csv file for each iteration.
You can have more variables substituted by just having one more column with the relevant variable name and using the same on your api call. Its just that simple. It did reduce a lot of manual work for me!!
You can also refer to the below link which guided me to use this feature in Postman. Link
Hope this will be helpful for someone.
Solution 2:[2]
I found the solution adding raw data as JSON
.
from Body > raw
[
{
"text": "Buy Milk",
"completed": true
},
{
"text": "Check updated of wall street",
"completed": false
},
{
"text": "Play game with team",
"completed": true
}
]
Solution 3:[3]
Lots of developer will use the answer of chethandb but the problem (if like me) is not only to execute requests in mass but also save the reponses somewhere.
- initial request
The RECIPIENTACCOUNT is a variable/parameter used in CSV and passed into each request.
- updating the initial request
Add the following code into the tab Tests:
let responses = pm.collectionVariables.get('collectionResponses')
if(responses) {
responses = JSON.parse(responses);
} else {
responses = []
}
responses.push(pm.response.json());
pm.collectionVariables.set('collectionResponses', JSON.stringify(responses));
Make a csv containing the parameters (in my case the ibans of the customers).
/home/rudy/Desktop/recipientaccount.csv
I do not disclose the recipient numbers of our customers.
Important to notice that RECIPIENTACCOUNT is used into the request as a parameter.
Then you are ready to go.
- Execution of the requests
Click on the arrow on the right (not displayed because it disappears).
Click on run. A new windows is opened.
Click on 'select File' to make a file selection and choose (for example) recipientaccount.csv.
Click on 'Save reponses'.
Change 'Iterations' (if needed).
You can 'preview' if you want.
Click on the blue button (Run Customer reachability in my example).
The requests are executed (sequentially).
I have limited the number of requests to 3 (the picture displayed '1', sorry) All the 3 requests were executed correctly.
- Now time to get the results.
Close the 'collection runner' window.
Back to 'Customer Reachability'
Click on the 3 dots on the right and on 'edit'
Click on variables and make a selection and copy the results from 'CURRENT VALUE':
[{"data":{"id":"NOT DISCLOSED","type":"zoomitCustomerSearch","attributes":{"customerReference":"0193:IBN_BE_NOT DISCLOSED","status":"not-reachable"}}},{"data":{"id":"NOT DISCLOSED","type":"zoomitCustomerSearch","attributes":{"customerReference":"0193:IBN_BE_NOT DISCLOSED","status":"not-reachable"}}},{"data":{"id":"NOT DISCLOSED","type":"zoomitCustomerSearch","attributes":{"customerReference":"0193:IBN_BE_NOT DISCLOSED","status":"not-reachable"}}}]
The results are one one big line. You have to make usage of sed/awk/... to format the resuls as desired.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | Saif |
Solution 3 | Rudy Vissers |