Variables are not substituted in the Performance run from uploaded data.json , while working correctly in functional run

Hi ,
I have a collection for performance testing , it reads data from the input data.json file , should be pretty much straight forward and works correctly in functional run , but when run performance test , variables values are not substituted .
Data in json looks like :

let initialData = 
    [
        {
            clientId:"",
            tenant:"",
            agents:[
                {
                agent_id:"",
                agent_token:""
                },
                {
                agent_id:"",
                agent_token:""
                },
                {
                agent_id:"",
                agent_token:""
                },
                {
                agent_id:"",
                agent_token:""
                },
                {
                agent_id:"",
                agent_token:""
                },
                {
                agent_id:"",
                agent_token:""
                },
                {
                agent_id:"",
                agent_token:""
                },
                {
                agent_id:"",
                agent_token:""
                },
                {
                agent_id:"",
                agent_token:""
                },
                {
                agent_id:"",
                agent_token:""
                }
            ],
            list:"",
            assets:[{asset_id:"",ip:""},{asset_id:"",ip:""},{asset_id:"",ip:""},{asset_id:"",ip:""},{asset_id:"",ip:""},{asset_id:"",ip:""},
            {asset_id:"",ip:""},{asset_id:"",ip:""},{asset_id:"",ip:""},{asset_id:"",ip:""},{asset_id:"",ip:""},{asset_id:"",ip:""},{asset_id:"",ip:""},{asset_id:"",ip:""},{asset_id:"",ip:""},{asset_id:"",ip:""},{asset_id:"",ip:""},{asset_id:"",ip:""},{asset_id:"",ip:""},{asset_id:"",ip:""}],
            policies:[],
            rules:[],

        }]

In each request in the collection we fetch data in pre-requisite scripts with code

var stringAgents = JSON.stringify(pm.iterationData.get("agents"));
var agents = JSON.parse(stringAgents);
var agent_token = agents[0].agent_token;
pm.collectionVariables.set("agent_token", agent_token);
var stringAssets = JSON.stringify(pm.iterationData.get("assets"));
var assets = JSON.parse(stringAssets);
var asset_id = assets[0].asset_id;
console.log("asset_id:" + asset_id)
pm.collectionVariables.set("asset_id", asset_id);
var ip = assets[0].ip;
console.log("ip:" +ip)
pm.collectionVariables.set("ip", ip);
var tenant = pm.iterationData.get("tenant");
console.log("tenant:" +tenant)
pm.collectionVariables.set("tenant", tenant);
var list = pm.iterationData.get("list");
console.log("list"+list)
pm.collectionVariables.set("list", list);

But every time when I run performance test , with data.json , 20 UV users with rump up period , I got 100% fails because variables that are expected in the request headers and authentication are not substituted


While when functional run with same data.json file , all data is substituted correctly

Please advise what am i doing wrong

Try this fixes

  1. Instead of setting collection variables, reference pm.iterationData directly in your request builder (URL, Headers, Body).
    Example: If your request needs {{agent_token}} , change it to use {{$iterationData.agent_token}} or construct it in the pre-request script as an environment variable.

  2. Use pm.environment.set("agent_token", agent_token) instead of collection variables.
    Note: Environment variables are better scoped for VU runs than collection variables.

  3. If possible, flatten your data.json so each row (object) contains all the variables needed for one iteration/VU. This avoids the need for dynamic variable-setting in scripts.

var agents = pm.iterationData.get("agents");
var agent_token = agents[0].agent_token;
pm.environment.set("agent_token", agent_token);

var assets = pm.iterationData.get("assets");
var asset_id = assets[0].asset_id;
pm.environment.set("asset_id", asset_id);
pm.environment.set("ip", assets[0].ip);

pm.environment.set("tenant", pm.iterationData.get("tenant"));
pm.environment.set("list", pm.iterationData.get("list"));

Then in your request, reference as {{agent_token}} , {{asset_id}} , etc.

Thank you @yonandualem unfortunately none of the proposed options worked , still functional runs are working fine but in performance variables are not substituted , tried with all possible options , environment , collection variables , global none was working .

  1. Flatten your data.json so each variable you want to substitute is a top-level key with a simple value—no arrays or objects.
  2. Reference variables directly in your requests:
    Use {{$iterationData.agent_token}}, {{$iterationData.asset_id}}, etc., in your request URL, headers, body, and auth fields.
  3. Remove all pre-request scripts related to variable setting for dynamic substitution. Only use pre-request scripts for logic/calculations not involving variable assignment for the current request.
[
  {
    "agent_token": "token1",
    "asset_id": "id1",
    "ip": "1.1.1.1",
    "tenant": "tenantA"
  },
  {
    "agent_token": "token2",
    "asset_id": "id2",
    "ip": "2.2.2.2",
    "tenant": "tenantB"
  }
]

Try this and let me know how it goes

Thank you @yonandualem i made my data structure flat and simple substituted {{agent_token0}} , {{asset_id0}} and etc and it worked . But i am getting new problem with authorization for totally valid tokens I am receiving in response header WWW-Authenticate: Bearer error=“invalid_token”, error_description=“An error occurred while attempting to decode the Jwt: Signed JWT rejected: Another algorithm expected, or no matching key(s) found”, error_uri=“RFC 6750 - The OAuth 2.0 Authorization Framework: Bearer Token Usage”

I checked all possible trailing spaces in data and encoding issues nothing should cause problem

Any thoughts on that ?

  • “Another algorithm expected, or no matching key(s) found”
    The server expected your JWT to be signed with a specific algorithm (e.g., RS256 vs HS256), or it can’t find the public key to verify the signature.

Common Causes

  1. Token Algorithm Mismatch
  • The JWT is signed with one algorithm (e.g., HS256) but the server expects another (e.g., RS256).
  1. Incorrect Signing Key
  • The key used to sign the JWT doesn’t match the public key the server uses to verify it.
  1. Malformed Token
  • The token is corrupted, has extra spaces, or is not well-formed (three parts separated by dots).
  1. Expired or Invalid Token
  • The token is expired or otherwise not valid.
  1. Test Data Copy/Paste Issues
  • Sometimes, copying tokens from Excel or JSON can introduce invisible characters or encoding problems. Even if you checked, try regenerating the tokens fresh.

@yonandualem I have checked tokens in JWT.io and they are valid

Thank you @yonandualem for help now evrything works :slight_smile:

1 Like

Glad I helped. Cheers!

2 Likes