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
44
votes
4 answers

How to set the request body via Postman's pre-request script?

I use Postman 6.0 to send an HTTP request. To send a request, I use a pre-request script to get a token and put it into the environment so that it will be used in the succeeding requests. The script below doesn't work because the body is not sent.…
richard
  • 1,845
  • 1
  • 20
  • 30
17
votes
2 answers

How to set basic authorization from environment variable in postman?

I want to set basic Authorization in Postman using environment variable. Because I have different authorization username and password for the different API calls. I set my postman according to below: In Authorization Tab: I've selected No Auth In…
Arbaz.in
  • 1,478
  • 2
  • 19
  • 41
16
votes
3 answers

Running a request in Postman multiple times with different data only runs once

I am new to Postman and running into a recurrent issue that I can’t figure out. I am trying to run the same request multiple times using an array of data established on the Pre-request script, however, when I go to the runner the request is only…
13
votes
1 answer

Postman scripting: how to decode token

I'm using postman with scripting. First, I perform a request to retrieve a oauth token. Then, inside the 'Test' tab, I'm using postman scripting to use the received token to set a global (postman) variable. Additionally, I would like to decode the…
12
votes
2 answers

How do I get current ISO8601 timestamp in Postman Pre-Query Script and Body?

Using Postman and the following code in pre-query script const moment = require('moment'); pm.globals.set("timestamp", moment().format("YYYY-MM-DDTHH:MM:SSZ")); I get as a response Request signature is too far in the past and has expired.…
Rhothgar
  • 121
  • 1
  • 1
  • 5
7
votes
2 answers

HMAC - SHA256 authentication via Postman

I'm trying to simulate webhook POST request to my Rails app (which works well in a real workflow) by Postman. I found lots of examples but none of them work - I keep getting a 401 code. What I did is defined headers and Pre-request Script like…
7
votes
1 answer

"TypeError: Cannot read property 'sigBytes' of undefined" error in pre-request CryptoJS script

I'm getting "TypeError: Cannot read property 'sigBytes' of undefined" error when running a postman collection with a cryptojs pre-request script. The pre-request script computes a hmac-sha256 signature which is also part of parameters of the main…
7
votes
1 answer

Postman - Cant run pm.sendRequest() in collection level pre-request script

Im using newman to run api tests after build in travis. Im trying to limit the duplication of pre-request scripts so checked out some workarounds on how can I have pre-request-scripts at collection level. My problem is that I dont want to run them…
7
votes
2 answers

How to add request parameters for a postman request in pre-script request

I want to add query parameters for my request in postman through the pre-request script. How can I do this?
Denise
  • 898
  • 1
  • 16
  • 30
7
votes
1 answer

postman sendRequest use authorization from collection

I can send a request in a Postman pre-request script as seen below. What I would like to do is use the same authentication as is set in the Collection so that if the Collection changes then my sendRequest follows suite. pm.sendRequest({ url:…
David Churchland
  • 292
  • 2
  • 11
6
votes
1 answer

Disable collection pre-request script at request level

I have a test collection in postman. I have a pre-request script to be run at the Collection level, but there are specific requests in the collection where I'd like the pre-request script not to run. How can I achieve this?
89f3a1c
  • 1,430
  • 1
  • 14
  • 24
6
votes
1 answer

OpenApi 3.0 requestBody required

I use postman and i create API with the openAPI 3.0. Problem is when i send this request, if i add body or not it return status code 200. I don't understand because i said i my code required for requestbody and for field in this body but nothing…
gaylord petit
  • 61
  • 1
  • 3
6
votes
2 answers

How to change Postman environment in pre-request script?

I'm having several collections of REST queries and tests in postman, and for each collection I've created a set of environment variables. I wish to make sure the right environment is selected before running the tests. Is there a way to automatically…
6
votes
2 answers

Converting crypto hmac to crypto-js hmac string

I'm trying to take the process of converting a secret hmac string to allow me to test my api in postman. Postman comes pre-installed with cryptojs. This is the process I've got on my test server using crypto: const crypto = require('crypto'); const…
6
votes
2 answers

How to clear console of postman programmatically

I'm trying to write assertions for api testing using postman. In order to debug I'm using console.log() function, which is cluttering the console of Postman. I've tried console.clear(); in pre-request script but get TypeError. Error in postman: Can…
1
2 3
21 22