Newman Modifying --env-var Parameter

I’m using Newman to run integration tests via Teamcity and a python script.

I’m using newman cli and --env-var parameters to pass in variables that I can’t store in github. Newman sends a request to my API with a different variable value than I passed in via env-var. I am assuming this has to do with the ‘$’ char. Everything between ‘$’ and ‘#’ is removed from the string. I’m at a loss as to how to correct it.

--env-var “password=12$123456?#12345”

Gets turned into: 12?#12345

The python script runs a newman cli command similar to this:

newman run integrationTests/API-Collection.postman_collection.json -e integrationTests/variables/devIntegration.postman_environment.json --delay-request 1000 -r teamcity,cli --env-var “username=someusername” --env-var “password=12$123456?#12345” --verbose --bail

Note the change in password below in the request sent by newman:

{
  "id": "f2b73f50-f136-47c8-aa13-fc65b7123456",
  "name": "Get MyAPI",
  "headers": {
      "accept": "application/json",
      "authorization": "Basic cantpastethishere",
      "user-agent": "PostmanRuntime/7.26.0",
      "cache-control": "no-cache",
      "host": "myhost.host.com",
      "accept-encoding": "gzip, deflate, br",
      "connection": "keep-alive",
      "content-type": "application/x-www-form-urlencoded",
      "content-length": 108
  },
  "method": "POST",
  "url": "https://myhost.host.com/my/route",
  "data": {
      "username": "someusername",
      "password": "12?#12345",
  }
}

Hey @jadams

From the command line, $ would allow you to use a system-level environment variable so it looks like it’s interpreting that value here.

What you could do is store that value as a system-level environment variable like this:

export PASSWORD='12$123456?#12345' 

Then use that with your Newman run command like this:

--env-var "password=$PASSWORD"

This will use that value in the Collection run.

I’m using the htmlextra reporter with the --reporter-htmlextra-showEnvironmentData flag to display what variable was used.

Thanks Danny, that got me going. Good catch and good eyes!

1 Like