Getting a value from a Post response to use in the next get call

Hello everyone. I was wondering if anyone can point me in the right direction.
I make a Post call that should return a response like this :

        {
    	"totalResult": 70,
    	"page": 1,
    	"pageSize": 25,
    	"pageResult": 25,
    	"cacheKey": "Cache:OfferingFilters:eyJTb3J0IjoxLCJGajEyIl19fQ==:Consolidated:Descending",
    	"result": [{
    		"tag": [{
    				"typeName": "AssetId",
    				"tagValue": [
    					"94846",
    					"87088",
    					"87089",
    					"85715",
    					"94847",
    					"94816",
    					"85716"    	
				    		]
    			},
    			{
    				"typeName": "AssetConsolidationId",
    				"tagValue": [
    					"227"
    				]
    			},

    			{
    				"typeName": "Bathroom",
    				"tagValue": [
    					0.0,
    					2.0,
    					1.0
    				]
    			},

    			{
    				"typeName": "ParentCategory",
    				"tagValue": [
    					"Rooms/Suites"
    				]
    			}
    		]
    	}, {
    		"tag": [{
    				"typeName": "AssetId",
    				"tagValue": [
    					"R94846",
    					"R87088",
    					"R87089",
    					"R85715",
    					"R94847",
    					"R94815"
    				]
    			},
    			{
    				"typeName": "AssetConsolidationId",
    				"tagValue": [
    					"228"
    				]
    			},

    			{
    				"typeName": "Bathroom",
    				"tagValue": [
    					0.0,
    					2.0,
    					1.0
    				]
    			},

    			{
    				"typeName": "ParentCategory",
    				"tagValue": [
    					"Rooms/Suites"
    				]

    			}
    		]
    	}]
    }

at this point, I just need any of the assetId returned:

so my script look something like this:

let consolidatedAssets = http.post(baseAPI + "/api/consolidated-assets", JSON.stringify(formdata2), filterAfterSearch)
 
resultsRT = ResultsResponseTrend.add(consolidatedAssets.timings.duration);
 
check(consolidatedAssets, { "Consolidated Assets": (r) => r.status === 200 });
 
//Parse consolidated Assets and get ID
 
let assetID = consolidatedAssets.json("result.1.tag.0.tagValue.0");

But I’m not getting anywhere anyone has any insights? it will be greatly appreciated
Thanks

Hi there, welcome to the forum :slight_smile:

I replicated your response in a mock server and your path of result.1.tag.0.tagValue.0 correctly returned R94846, so I’m not sure what the issue is. Your script looks OK, so you don’t seem so clueless to me… :slight_smile:

What are you expecting and what are you seeing on your side? Also which k6 version?

You can use console.log() or --http-debug to troubleshoot the response and the JSON path.