Hi, I want to pass multiple inputs using an Array to the request body and get the response. Can someone please help me on this?
Body:
[
{
"mfid": "{{mfid}}",
"secType": "OE"
}
]
Pre-request Script:
let mfidValues = pm.collectionVariables.get('mfidValues')
if(!mfidValues || mfidValues == 0) {
mfidValues = ['22052', '22054'];
}
let currentMfId = mfidValues.shift();
pm.collectionVariables.set("mfid", currentMfId);
pm.collectionVariables.set("mfidValues", mfidValues);
Tests:
var jsonData = pm.response.json();
var mfidValues = pm.collectionVariables.get('mfidValues');
if (mfidValues && mfidValues.length > 0) {
postman.setNextRequest("ListFees")
}
else {
postman.setNextRequest(null)
}
As of now it is working now for one field i.e. “mfid”. Is there any way I can pass the inputs for multiple fields in the body using the same array i.e. to secType as well like below.
mfidValues1 = ['22052', 'OE'];
mfidValues2 = ['3668', 'CE'];
Hey @ramofficial1
Is there anything you can get from this topic and the thread?
It seems like the same code being used. There are other similar questions in the community with the same code too.
Ok your last message was telling of what was wrong.
Your prerequest script in fact is resetting the array every time.
Pre-request script:
var buyerProgramId= [‘1961’, ‘1962’, ‘1972’, ‘1976’, ‘1977’];
pm.globals.set(“buyerProgramId”, JSON.stringify(buyerProgramId));
This is where you want to do your array manipulation. You should be popping the array and saving the new contents here.
let buyerProgramId = pm.globals.get('buyerProgramId');
if(!buyerProgramId){
buyerProgramId= ['1961', '1962'…
or maybe this other topic:
Here is some example code. I’m using Postman Echo with a POST request to emulate your response, with the loop being a GET request with the filesystem being echoed back as a parameter.
[image]
This is the body I’m working with.
{
"filesystems": [
{
"name": "fs1",
"root_permissions": "775",
"mountpoint": "/{{ old path }}/fs1"
},
{
"name": "fs2",
"root_permissions": "775",
"mountpoint": "/{{ old path }}/…
Thanks Danny. I got the solution by referring to Allen Helton code
1 Like