I have requests that require a token. Its passed in the header for the request as a key value pair with the key being access_token and the value being its value. Now different formats of the access token needs to be supported. eg: AccessToken,Access-Token,Access_Token. Is there any way I can verify it?
Asked
Active
Viewed 33 times
-1

Rohith R Nair
- 43
- 1
- 10
1 Answers
1
First set up two arrays as environment variable :
pm.environment.set("header",["access","acces2","access3","aaccess4"])
pm.environment.set("header_temp",["access","acces2","access3","aaccess4"])
After that delete the above lines from script and below line to your pre-request script:
replace pass_2 with the request name you are trying
pm.environment.get("header_temp").length === pm.environment.get("header").length ? pm.environment.set("header", pm.environment.get("header_temp")) : null
let header = pm.environment.get("header")
let header_temp = pm.environment.get("header_temp")
if (header.length !== 1) {
console.log(header.length)
pm.environment.set("token", header.pop())
pm.environment.set("header", header)
postman.setNextRequest("pass_2")
console.log("pass_2")
} else {
pm.environment.set("token", header.pop())
pm.environment.set("header", header_temp)
postman.setNextRequest(null)
console.log("null")
}
Set header as a variable token:
Now open collection runner and run it , you can see that single request was send 4 times with those 4 headers
You can try below collection that I created:

PDHide
- 18,113
- 2
- 31
- 46