I want to automatically add a header to every request in my whole collection using this pre-request script:
pm.request.headers.add({
\'key\': \"myvar\",
In test section of login, use this script to remember token in Environment
var jsonData = JSON.parse(responseBody);
tests["Body contains result"] = responseBody.has("result");
var result = jsonData.result
tests["result contains user"] = result.user !== null
var user = result.user
tests["result contains token"] = result.token !== null
var token = result.token
var accessToken = token.accessToken
var refreshToken = token.refreshToken
postman.setEnvironmentVariable("accessToken", accessToken);
postman.setEnvironmentVariable("refreshToken", refreshToken);
in every call wihich requires token, use token like this in header section
Authorization = Bearer {{accessToken}}