Newman unable to read Date from Variables but it's working fine in Postman client

My question: I am trying to read the value of Date from the variable, it’s working fine in Postman, when I am executing it from CLI with newman, it’s reading as blank, like this (', ‘’ OR ', undefined)

Details (like screenshots):

I tried to read from Collection and Environment variables both, like below, but no luck

console.log("from collection variable: ",pm.collectionVariables.get(“checkin”));

console.log("from env variable: ",pm.environment.get(“checkin”));

Apart from Date(2023-04-15), other values are able to read without any issue by Newman, could be some special character issues, need help to fix.

@danny-dainton any thought, how to handle this in newman

What’s the Newman command that you’re using?

Is the variable at the Collection or Environment level?

I would need to know/see more details to give a better answer :sweat_smile:

Hi @danny-dainton

I am keeping the Date value in the Collection variable, and also keeping it in the environment variable since Newman is unable to read Date data from the collection variables, but I am not getting success in either case.

I am keeping Date in Collection and Env variable as below

This is how I am trying to access Collection and Env variable

console.log("from response: ",res.booking.bookingdates.checkin);

console.log("from collection variable: ",pm.collectionVariables.get(“checkin”));

console.log("from env variable: ",pm.environment.get(“checkin”));

No issue in the Postman client, able to read all the variable Data as below

When I am trying to execute via Newman with the help of the below command, Newman able to read all the collection and env data apart from Date

Newman run Collection.json -e Environment.json -r cli

this is what, I am getting garbage data via Newman, see the below snap-shot, I want the actual Date value should get via Newman from Collection OR Env variable

image

Is this static data in the variables or is this placed in there, via a script, during the execution of the collection?

I have the value saved in an environment file and ran this basic request with Newman.

Not sure if there is something else going on here. I don’t know exactly what you have in the Collection or what your Newman version is either. :thinking:

Hello @danny-dainton,

Thanks for your time and for compiling the same at your end.

FYI, Data is static, which I have put in the variable.

It worked for me as well, I tried to fetch data from env as per your approach

:white_check_mark: console.log("from env variable: ",pm.variables.get(“checkin”));

Why is this not working another way in Newman as mentioned below?

  1. For a collection’s variable with the below approach

:x: console.log("from collection variable: ",pm.collectionVariables.get(“checkin”));

  1. For the environment’s variable with the below approach (Please note, as mentioned above, it’s working with pm.variables.get(“checkin”) )

:x: console.log("from env variable: ", pm.environment.get(“checkin”))

Hello @danny-dainton, did u get a chance to have a look at the previous message, I am unable to get the Date from Collection’s variable, using the below way to get the Date (2023-04-15) data, looks like this is an issue in Newman, please check and confirm.

console.log("from collection variable: ",pm.collectionVariables.get(“checkin”));

Environment variables do work with Newman.

Remove the ‘checkin’ variable from everywhere apart from the environment to avoid any issues with scope.

Use the pm.environment.get() function to retrieve.

For troubleshooting purposes, you may want to define a local variable and then console log that.

const checkinLocal = pm.environment.get("checkin");
console.log("from environment variable: " + checkinLocal);

// or use Template literals to interpolate variables (aka backticks)

console.log(`from environment variable: ${checkinLocal}`);

JavaScript Template Literals (w3schools.com)

pm.variables will basically go through the whole scope trying to resolve the variable.

Local, collection, then environment if I remember rightly.

In one of your screenshots, you have the URL set as an environment variable. Try console logging that as well.

Thanks @michaelderekjones for the response

I am able to resolve this with the help of > pm.variables.get() function, able to retrieve data from the environment OR collection variable.

Want to understand more about >pm.collectionVariables.get() function, since I am keeping Date value in checkin collection variable able to retrieve data in postman client which is not happening in Newman

Trying to read the above checkin variable with the help of the below function

console.log("from collection variable: ",pm.collectionVariables.get(“checkin”));

Getting actual Date in Postman client whereas Newman reading this as garbage value

Just want to know, why this is happening.

Good news, this issue has been fixed automatically, don’t know how?, did Postman push any update for this? same function able to fetch the data (especially Date format data)

Earlier I was getting garbage data via Newman for the below function while reading data from Collection and env, now newman able to fetch Date format data correctly

console.log("from response: ",res.booking.bookingdates.checkin);

console.log("from collection variable: ",pm.collectionVariables.get(“checkin”));

console.log("from env variable: ",pm.environment.get(“checkin”));

now neman is able to fetch the data correctly

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.