Setting postman env var via Postman App - number stored as string

When I’m setting an environment variable via the Postman App, it’s setting my numerical value as a string.

As a result this test fails:
With this error:
AssertionError: expected 759390 to be one of [ '759390', 824128 ]

Notice that the first “oneOf” is wrapped in a string? That var was set via Postman App, where as the 2nd var was set using a response body from a prior call, using pm.environment.set()

I’m not really sure I see a way to override this and set a number (id) as a number type in the UI/App. Help would be appreciated, thank you in advance!

Hey @cekeren :wave: Welcome to the Postman Community :tada:

If you want to convert a string to a number, you can do:

const numId = Number(pm.environment.get('id'))
pm.environment.set('id', numId)

Hope this helps!

1 Like

Hey there, thank you! Yes - this helps. I had half-thought “I could convert the var before testing” but I was hoping there was a better way of setting it at the UI/App level. This still gets me to where I need to be though, thank you!


PS - thank you so much for the quick response, let alone the response! The community is just another reason why I convert all of my peers/colleagues to Postman for API anything!