Collection variable as a JSON object is not working in newman

I am working on a test script where i am using collection variables to for storing tokens and use it in subsequent calls. Now instead of single variable I used JSON object to make sure one type of data stores in one object. It is working fine in collection Runner. However , in newman it is showing undefined. is new newman unable to handle json object as a variable.
here are the screenshot.
pre-requisite of call 1:
image !

set value in test of call 1

image

now accessing it in next call like

image

this is working fine in runner. why it is not working in newman?

Hey @sanu1991,

Could you post the actual code snippets rather than images of them, please? It would make things easier for others to work through it locally. :slight_smile:

HI @danny-dainton, sorry for my late reply. i was trying from my end. i have taken a small example to simulate the same as i cannot share the actual api as it is private business data and i do not have permission.
when i run the coll using postman runner it is working fine. However, the newman unable to parse the json object which i defined in the pre-requisite of the first call.
I am unable to attach the file.

`{
"info": {
	"_postman_id": "01634f51-c026-45aa-812f-b7f6be135166",
	"name": "northwind",
	"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
	{
		"name": "Get all customer",
		"event": [
			{
				"listen": "prerequest",
				"script": {
					"id": "45599bfa-c252-4995-83b1-52335cec4c79",
					"exec": [
						"pm.collectionVariables.set(\"businessData\",\r",
						"    {\r",
						"        \"customer\": \"\"\r",
						"    }\r",
						");"
					],
					"type": "text/javascript"
				}
			},
			{
				"listen": "test",
				"script": {
					"id": "83954879-0523-46a8-8709-16b1372fa40b",
					"exec": [
						"//Get the collection json object auth data\r",
						"let busiData = pm.collectionVariables.get(\"businessData\",);\r",
						"let jsonData = JSON.parse(responseBody)\r",
						"busiData.customer = jsonData.value[0].CustomerID;\r",
						"\r",
						"pm.collectionVariables.set(\"businessData\", busiData);\r",
						"\r",
						"console.log(busiData);\r",
						""
					],
					"type": "text/javascript"
				}
			}
		],
		"request": {
			"method": "GET",
			"header": [
				{
					"key": "Accept",
					"value": "application/json",
					"type": "text"
				}
			],
			"url": {
				"raw": "https://services.odata.org/Northwind/Northwind.svc/Customers?$top=1",
				"protocol": "https",
				"host": [
					"services",
					"odata",
					"org"
				],
				"path": [
					"Northwind",
					"Northwind.svc",
					"Customers"
				],
				"query": [
					{
						"key": "$top",
						"value": "1"
					}
				]
			}
		},
		"response": []
	},
	{
		"name": "get one customer",
		"event": [
			{
				"listen": "prerequest",
				"script": {
					"id": "50d1a3a9-6559-4da3-bf29-fed05c82da15",
					"exec": [
						"//Get the collection json object auth data\r",
						"let busiData = pm.collectionVariables.get(\"businessData\",);\r",
						"\r",
						"let customer = busiData.customer;\r",
						"console.log(busiData);\r",
						"let url = \"https://services.odata.org/Northwind/Northwind.svc/Customers(CustomerID='\" + customer + \"')\"\r",
						"pm.request.url = url;\r",
						"\r",
						"\r",
						"\r",
						"\r",
						"\r",
						""
					],
					"type": "text/javascript"
				}
			}
		],
		"request": {
			"method": "GET",
			"header": [
				{
					"key": "Accept",
					"value": "application/json",
					"type": "text"
				}
			],
			"url": {
				"raw": ""
			}
		},
		"response": []
	}
],
"variable": [
	{
		"id": "cdcbeab8-2443-4719-acc7-2f44def7156d",
		"key": "businessData",
		"value": "",
		"type": "string"
	},
	{
		"id": "5fa8ed18-06be-4a3a-839b-e29b900997f7",
		"key": "customer",
		"value": "",
		"type": "string"
	}
],
"protocolProfileBehavior": {}

}`

so here is the coll file. please let me know for further info.

Having a similar issue within newman, you guys had any luck yet?

Collection runner does exactly what it needs to, but as soon as I do the cli run via newman I get 404 responses, which show that something isn’t being passed along correctly (I expect a 204.) Is there a way to get the logs for the newman run to troubleshoot it a bit more diligently?

@kakkiesbarr Not yet. I raised the same issue with Postman github issues.

they marked it as a bug. but given a workaroud. i did not try it as i proceed with single variable.

if you try this let me know does this work or not.

~Swastik

I managed to sort my issue out. Made sure I was resetting the variables before the run, and also saw that I wasn’t adding a header which was required, so unfortunately it seems a little different to your issue.

Best of luck!