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