Access to collection variables in Postman

Function

Postman has added collection support for variables, authorization, preliminary request, and test scripts. (since version 5.4.1 this exists both at the collection level and at the folder level)

Use case

Let's say I want to keep the update token when the entry endpoint is hit. My test script should create / update the COLLECTION variable, not a global or environment variable.

Once this refresh_token is available for collection, other tests and pre-request scripts, I think there is access to them through an API similar to pm.environment or pm.globals. (e.g. pm.collection)

Question

I cannot find any documentation on how to access or modify it using pre-query scripts or tests ... does anyone know how to do this? Maybe this was not thought out fully or not fully implemented, but I thought that I would take care of helping others.

Temporary solution

As a complete hack, I store the things I need as environment variables replaced by it. It is not perfect (it makes things messy when working in other collections), but it works great.

+4
source share
1 answer

Collection variables

You can access the collection variables (and all variables) in the pre-query and test sections of the script using pm.variables.get("variableName").

.

.. , pm.environment.set() to reset pm.environment.unset(), .

+4

Source: https://habr.com/ru/post/1690342/


All Articles