How to pass argument or value while running collection from newman

How to pass argument or value while running collection from newman ?

newman run mycollection.json -e envfile.json/csv is not working

Scenario

I have a collection which can run on multiple environments seamlessly but i need to pass one argument/value in first API request body which while drive to run on multiple environment

Steps to reproduce the behavior:

  1. Go to newman
  2. Run collection

I need to know how can i run collection by passing one value in command line

Collection link
https://www.getpostman.com/collections/ca4042cf3c3280013986

In above collection i need to pass organization id in first API

API name getDomain API
Request body
{“orgid”: “give_org_id_here”}

Could you please let me know the solution for this ?

I tried many things like passing environment json/csv file but nothing worked because environment json/csv files have only variable key doesn’t have variable value

You can specify environment or global variables directly on the CLI like this:

–global-var “foo=bar”

Does it provide you with a solution?

1 Like

Hi vdespa,

Thanks for your response,

But it is not working

Here is the scenario

In my collection , i need to pass value for the first API

Below is the Request body of first API to which i need to send value form CLI

{
“orgid”: “{{domain}}”
}

In above request body {{domain}} is the user defined variable name to which i need to send value from CLI

below command i am using as per your suggestion

newman run mycollection.json -global-var “domain=value” , its giving me below
error: unknown option -o

newman run mycollection.json -g “domain=value” , its giving me below
error: ENOENT: no such file or directory, open ‘C:\Users****\Desktop\27082019\domain=00D1U000000GqnbUAC’

It looks like you’re using the -g flag which would be telling Newman to use a global variable file path or URL.

You need to use --global-var to pass in the argument like you’re doing in the command.

Hi

Thank you

It worked with below command …

–global-var “=”

1 Like

This doesn’t make sense to me. Was the markup (markDown?) malformed?

  1. the em-dash probably should be --and the curly-quotes should be straight "
  2. there should be a variable name left of the equals and a value on the right.

Those quotes marks are a discourse copy/paste quirk :confused:

The issue was that they were using an incorrectly formatted command, with a single leading dash, to specify a single global variable from the command line.

The second attempt to run the command, the -g was used and that’s for specifying a file location to read all the global variables.

Ah-ha, I fell for the forum’s copy-and-paste bug myself. Was puzzling over why it wasn’t working, only to discover that I had been using the invalid curly-quotes from earlier examples. Once I literally straightened them out, it worked!

  • Bad: –global-var “k=v” ; // bad em-dash & curly-quotes
  • Good: --env-var "ev=5999222 ; // good double-minus & straight-quotes"

References:

  • issue 764 --global-var option added on Aug 22, 2017
  • issue 1799 --env-var option added in Newman v4.4.0.
1 Like