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
1
vote
0 answers

Read an array of arrays in json file when I run a collection postman

I don't know what to write in the param value in the body using postman to read data from a json file, when the jsonfile has an array of arrays like you can see: I have a json file with this information In the request body I write that value for…
1
vote
0 answers

The authorization on the header is not taken into account in my pre-request script

I am trying to establish a pre-request script in postman but I get error "Full authentication is required" because when I send the authorization in the header it is not being taken into account (As I see in the console). This is strange because when…
1
vote
0 answers

How to get collection request name at newman cli postman

I want to save my all response file with their request name. So I am finding a solution where I get the request name. Newman CLI is a command-line tool to run the postman collection but I read out all documentation and not get any solution for the…
1
vote
1 answer

How to break a for loop when response code is 200

In the below script I am trying to break the for loop once I get the status code as 200, but requests keep happening even after receiving status code 200. var getLibraries = host+'webcontents/libraries'; pm.sendRequest(getLibraries, function (err,…
1
vote
3 answers

Postman with Pre-request Scripts: "Error: Parse Error: Header overflow"

I was having this problem only when running requests for a local application with some Pre-request Scripts: Error: Parse Error: Header overflow The Postman version was: v7.25.0. PS: For the same request for my server application, I wasn't received…
Marcelo Toledo
  • 128
  • 2
  • 13
1
vote
0 answers

Testing API using postman: I want to validate language code in url(href) using postman

I am sending request in multiple language(say en,de) and I have stored res of all href link present in body.I want to validate if href in response has valid language code or not. href appears in response has language code as…
1
vote
0 answers

Creating an AES encrypted header value in Postman

To authenticate into a document retrieval API, I'm passing an encrypted string as a custom header value called ciphertext using a pre-request script. Is there a better/cleaner way of doing this? var interface_name = "interface name"; var password…
j8d
  • 446
  • 7
  • 23
1
vote
1 answer

Postman pre-request script for Auth, actual POST call returns Invalid Token

forgive my lack of tests and error logic. I know my pre-request script is working but for the life of me I can't figure out why the subsequent POST request fails with "Invalid token". I'm using Postman to execute a pre-request script for auth and…
Jeremy Fiel
  • 140
  • 10
1
vote
1 answer

Request body variable from JSON not accepting integer values

My sample JSON file for postman runner: [ { "name": "runner", "hitler_id": "4006abc", "year": "2017", "boolean": "false", "expected": 717962 } ] Pre request script: var member = data.name; var booking = data.boolean; var fyyear = data.year; var sid…
1
vote
2 answers

How to validate POST request body required params in Pre-request script?

I have few need-to-have params in JSON raw data in my request body and I want to validate in the pre-request script in Postman if those params are present in the body or not. { "stores": [ { "city": "Tokyo", "name": "Church…
Pruthvi K R
  • 13
  • 1
  • 3
1
vote
0 answers

Postman Pre-request Script does not exclude fields

I am trying to exclude fields from response that is returned from elasticsearch using postman pre-request script but looks like exclude is not working as expected. Below is my pre-request script - pm.sendRequest({ url: 'https://' +…
Jon Abraham
  • 851
  • 3
  • 14
  • 27
1
vote
0 answers

APIs are not running in iterations after running a multiple request api

/api/stores triggers an array of different data in postman: #pre-request script var managers= pm.globals.get("managers"); var ref= pm.globals.get("ref"); if(!managers && !ref){ managers=[0,1]; ref=["QA0","QA1"]; } var…
1
vote
1 answer

Postman - calling function in external JS file - 'x is not defined'

Other posts have dealt with this question, but I continue to be unable to apply this myself. I have a Postman pre-script test. I am trying to call an encryption function defined in http://some-server:port/lib/forge/forge.min.js The code calls the…
Guy
  • 666
  • 1
  • 10
  • 34
1
vote
1 answer

Postman pre-request script: Can't access header from response

I am writing the following pre-request Script to get my JWT for authentication: pm.sendRequest(echoPostRequest, function (err, res) { console.log(err, res, typeof res); if(err === null){ console.log(res.header) // var…
Max
  • 1,368
  • 4
  • 18
  • 43
1
vote
1 answer

How to set environment variable using a data file in Postman

I have a data file having a column userid, now i want to set a environment variable based on the value of userid using pre-request script. var i = data.userId; console.log(i); if(i==='1') { pm.environment.set("id","i"); …