Handling multiple dynamic values

Hi,

I have below response and below 2 scenarios to be done:

  1. Take “id” from response randomly and use it in next request
  2. Take all "id"s in array and iterate through all in next request
    {
    “count”:4,
    “results”:[
    {
    “companyDetails”:{
    “id”:“123”,
    “name”:“abc”,
    “URL”:“www.abc1.com
    }
    },
    {
    “companyDetails”:{
    “id”:“345”,
    “name”:“def”,
    “URL”:“www.abc2.com
    }
    },
    {
    “companyDetails”:{
    “id”:“678”,
    “name”:“ghi”,
    “URL”:“www.abc2.com
    }
    },
    {
    “companyDetails”:{
    “id”:“901”,
    “name”:“jkl”,
    “URL”:“www.abc2.com
    }
    }
    ]
    }

Thanks

Run this request in setup function. And return this request in setup.E.g.

export function setup() {

  let operatorAuth = Load.auth(Roles.Operator);
  let createResponse= http.post(
   'htttp://test.com.cv',
    JSON.stringify({
      config: [
        {
          amount: 1000,
        },
      ],
      operation: "x",
    }),
    {
      headers: {
        "Content-Type": "application/json",
      }
    }
  );

  return [
    operatorAuth.json(),
    createResponse.json(),
  ];
}

When return the response body you can take all ids.data[0] represents operatorAuth.json() , data[1] represents the createResponse.json();

export default function(data){     
`${data[1].results.id[(totalVu * (exec.vu.iterationInInstance)) + (exec.vu.idInTest - 1)]}`

}

If u want only take the random id,you can use same format,because when u run parallel you will take error. ${data[1].results.id[(totalVu * (exec.vu.iterationInInstance)) + (exec.vu.idInTest - 1)]}
this take id in body per iteration.You can think this formula below;
${data[1].results.id[0]},
${data[1].results.id[1]},
${data[1].results.id[2]},
…until last index in the body