How to get parts of response to a request in a dynamic way?

  • We have three requests; A, B and C.
  • A and B fetches information that is used in C’s request body.
  • A’s response body and C’s request body are similar but not equal.

Response A:

   {
    	"id": {
    		"value": 112233
    	},
    	"fields": [
    		{
    			"id": 155,
    			"defId": 812,
    			"key": "AB",
    			"type": "entity.field.value.TextFieldValueEntity",
    			"typedFieldDefinitionId": "812"
    		},
    		{
    			"id": 159,
    			"defId": 808,
    			"key": "CD",
    			"type": "entity.field.value.TextFieldValueEntity",
    			"typedFieldDefinitionId": "808"
    		}
    	],
    	"indicators": [],
    	"definingSupportComponentUuid": "1d5d7728-c58b-4568-9e27-6d89c571c272"
    }

Request body C

   [
    	{
    		"id": 155,
    		"defId": 812,
    		"key": "AB",
    		"name": "Lorem ipsum",  //from iterationdata
    		"versionId": 123,                //from request B
    		"type": "entity.field.value.TextFieldValueEntity",
    		"typedFieldDefinitionId": "812"
    	},
    	{
    		"id": 159,
    		"defId": 808,
    		"key": "CD",
    		"name": "Ipsum lorem",
    		"versionId": 321,
    		"type": "entity.field.value.TextFieldValueEntity",
    		"typedFieldDefinitionId": "808"
    	}
    ]

I understand how to do this: In request A and B iterate the responses and store the information in for example collection variables and then use these variables in request C.

The problem is that the number of fields are quite big and also the number of values fetched from each field; it will end up in approx 600 variables to be extracted and used.

My question is if this can be done in another way. From googling I understand that if response A and request C are equal there is a way to store the response json as a string and then put it in the request but that’s not possible in my scenario.

Below I will try to describe what I want to achieve. I understand that it cannot be done as I present it but it will give the idea of what I want:

In the Test section of request A:

var field_list = (responseJson.fields).length;
for (var i = 0; i < field_list ; i++)
{
pm.collectionVariables.set(responseJson.fields[i].key, responseJson.fields[i].id);
}

and then in request body C fetch the value:

“id”: {{AB}}.id,
“defId”: {{AB}}.defId,
“key”: “{{AB}}.key”,

Is there any way to achieve above? I want to avoid creating a lot of variables and use a more dynamic approach but I cannot see how to given the limitations of javascript and Postman.

If I understand your question correctly. You want to use responses from request A&B and create a request C that contains data from both responses.

Instead of creating many variables, you can store responses from request A and B in 2 variables and then use those 2 variables in pre script. Then create your final request which u need to pass.