Patrick Puente
1 min readMay 11, 2020

--

Hey Gary,

If you copied the method in your previous response from your test’s code, I think we’ve found the problem: It should be pm.collectionVariables rather than pm.coolectionVariables.

In case it’s not that simple: it sounds like your Postman version is up to date, so that’s not the issue. That’s an interesting idea aboutdeclaring the variable before attempting to unset it. To test, I put together this collection which simply gets https://google.com, then runs two lines of JS:

pm.collectionVariables.unset('some-new-var')
throw new Error('this is an error')

The result: you get a “this is an error” error in console. But without that second line, there are no errors in console. So, attempting to unset a variable before it has been declared does not appear to throw an error.

Technically, you could simply skip the unsetting step. I do it to make sure that if the set method fails, the values from my previous run won’t be retained. Retaining variables from previous runs have sent me on some wild goose chases before, so I make a point to clear them now. But, if you don’t unset the previous variable, then pm.collectionVariables.set will simply overwrite the existing value.

You can download my version of the collection described by this article with the “Run in Postman” button here: https://documenter.getpostman.com/view/45334/SWTEbbQU?version=latest. After configuring your environment with your store’s API keys, you should be able to step through each of the requests in the collection to compare with the results from your collection.

--

--

Patrick Puente
Patrick Puente

Written by Patrick Puente

Musician, Taco Enthusiast, and Solution Architect

Responses (1)