Questions tagged [postman-pre-request-script]

Use this tag for issues with pre-request scripts in postman, use the "postman" tag for general issues

Reference:

319 questions
5
votes
2 answers

Postman: Access environment variables or read from file

I'm trying to test an API that needs AWS credentials (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY and AWS_SESSION_TOKEN). Right now I'm setting them explicitly in the Postman environment, but I need to do this every time I'm refreshing my…
Nino
  • 429
  • 2
  • 8
5
votes
1 answer

How to generate future date and time for postman request

{ "name": "IronMan", "phone_number": "555555555", "number_of_guest": 10, "tables": [ 2 ], "reservation_start_at": "2020-10-15T10:00:00.861873Z", "reservation_end": "2020-10-15T11:00:00.861873Z" } I am stuck at…
TQJ
  • 65
  • 2
  • 6
5
votes
0 answers

Postman - Access Token Retrieval using Authorisation Code grant type

I have set up a release pipeline to automatically deploy an API artefact to a particular domain, and as part of that pipeline I have introduced the execution of a postman collection via the Newman CLI, the ultimate goal that I want to achieve with…
5
votes
1 answer

Postman getting random UserName inside Pre-Request Scripts

I'm wanting to generate a random user to be created using the API, every time I run the request. I have an email environment variable which I want to be set to a random email every time the user create request is sent. I currently…
4
votes
1 answer

Sending a Post request in postman pre-script

I am trying to send POST request in a pre-script using postman but getting error "There was an error in evaluating the Pre-request Script: Error: Unexpected token '<' at 1:1 ^". Not sure whats wrong. Can anyone help me with…
DevSay
  • 886
  • 1
  • 14
  • 32
4
votes
1 answer

postman 'There was an error in evaluating the Pre-request Script' but pre-request script is empty

I have a shared collection on Postman. When I run the request in the shared collection it fails with the following error: There was an error in evaluating the Pre-request Script: Error: Unexpected token '<' at 1:1 ^ I have tried this with…
richflow
  • 1,902
  • 3
  • 14
  • 21
4
votes
1 answer

Access Global Variable Initial Value

Does anyone know of a way to access a global variables initial value? I know you can access it's current value through: pm.environment.get("variable-key"); I am working on a pre-request script that would benefit from accessing an initial value so…
Dan Whitehouse
  • 548
  • 1
  • 6
  • 18
4
votes
3 answers

In POSTMAN how do i get substring of response header item?

I am using postman to get response header value like below: var data = postman.getResponseHeader("Location") . //value is "http://aaa/bbb" for example I can print the value via console.log(data) easily. However, what I really want is "bbb". So I…
user1559625
  • 2,583
  • 5
  • 37
  • 75
3
votes
1 answer

How to get auto-generated headers with pm.request.headers in Postman?

I have a Postman pre-request script which uses pm.sendRequest to call an endpoint that uses the same authorisation as the current request. I tried to use pm.request.headers in the script to get the Authorization header so I could add the same header…
AndrWeisR
  • 1,110
  • 11
  • 21
3
votes
1 answer

Postman: add a given header to all requests in the given collection or collection-level header

My question: Postman: add a given header to all requests in the given collection or collection-level header. Details (like screenshots): I have “x-apikey” header & a bunch of requests in the collection without this specific header. How can I avoid…
Optimism
  • 167
  • 1
  • 8
3
votes
1 answer

Postman Get value of url request parameter to do a test

I am trying to get a url from the get request params. How to Construct request URL from environment variables In Pre-request script urlwfsservice and orderid is set from environment…
3
votes
1 answer

Postman running the same request multiple times

I want to run the same request multi times with different pre-request scripts? Any idea how can I do it without using the Data Driven (CSV) test? Eg., I have to run the below GET url multiple times (every 2 minutes) but whenever I run this, I need…
siv
  • 49
  • 1
  • 1
  • 2
3
votes
1 answer

Postman nested variables not parsed in when get environment variable in Pre-Request script

Imagine following environment variables: Base-URL => https://my.website.com/api Cars-URL => {{Base-URL}}/cars Auth-URL => {{Base-URL}}/login If I use GET {{Cars-URL}} in postman it works fine and it does a call to…
hwcverwe
  • 5,287
  • 7
  • 35
  • 63
3
votes
2 answers

Postman : how to rerun a subset of postman request multiple times

I have a postman request in the below order GET Request GET Request POST Request POST Request <<< POST Request <<< Need to repeat only 4,5,6 - 10 times POST Request <<< POST request 4 , 5 and 6 needs to repeated (say 10 times) I tried copy of…
supersrin
  • 43
  • 3
3
votes
1 answer

Postman- Pass dynamic parameters to collection at run-time which is not part of response

I have created postman collection for unit testing of APIs. I need to handle below scenario. My second API generates OTP and sends it over email but its not part of response. I want to pass that OTP in request body of 3rd API. I am executing postman…
1
2
3
21 22