# Unable to read pre request script while running postman CLI

**URL:** <https://community.postman.com/t/unable-to-read-pre-request-script-while-running-postman-cli/68769>\
**Category:** Help Hub\
**Tags:** tests\
**Created:** [September 23, 2024, 3:11pm UTC](https://community.postman.com/t/unable-to-read-pre-request-script-while-running-postman-cli/68769 "2024-09-23T15:11:11Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ameneh1986](https://avatars.discourse-cdn.com/v4/letter/a/9f8e36/32.png) [@ameneh1986](https://community.postman.com/u/ameneh1986)\
**Post date:** [September 23, 2024, 3:11pm UTC](https://community.postman.com/t/unable-to-read-pre-request-script-while-running-postman-cli/68769/1 "2024-09-23T15:11:11Z")

</div>

I have pre request script in my postman test. When i am running manually via postman GUI, there is no issue and it is reading the pre request script but when i tried to run through CLI using API key, it seems that it is not reading the pre request script and all my test which have pre request script is getting failed.  
Any config required to read pre request during running from CLI?

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [September 23, 2024, 3:12pm UTC](https://community.postman.com/t/unable-to-read-pre-request-script-while-running-postman-cli/68769/2 "2024-09-23T15:12:21Z")

</div>

Hey @ameneh1986 👋🏻

Welcome to the Postman Community :postman:

Could you provide more context about the script and what the script is actually doing, please?

---

<div class="post-metadata">

**Author:** ![ameneh1986](https://avatars.discourse-cdn.com/v4/letter/a/9f8e36/32.png) [@ameneh1986](https://community.postman.com/u/ameneh1986)\
**Post date:** [September 23, 2024, 4:46pm UTC](https://community.postman.com/t/unable-to-read-pre-request-script-while-running-postman-cli/68769/3 "2024-09-23T16:46:06Z")

</div>

Hey @danny-dainton  
Below is details in my pre request:

```auto
// Generate a current timestamp in ISO format
var currentDate = new Date();

// Generate a random number of days (1 -30)
var randomDays = Math.floor(Math.random() * 30) + 1;

// Add the random no of days to the current date and update date and save in env:

currentDate.setDate(currentDate.getDate() + randomDays);
var randomIsoTimestamp = currentDate.toISOString();

pm.environment.set("randomIsoTimestamp", randomIsoTimestamp);

```

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [September 23, 2024, 4:57pm UTC](https://community.postman.com/t/unable-to-read-pre-request-script-while-running-postman-cli/68769/4 "2024-09-23T16:57:15Z")

</div>

What’s the Postman CLI command that’s being used and the version of the CLI that you’re using?

---

<div class="post-metadata">

**Author:** ![ameneh1986](https://avatars.discourse-cdn.com/v4/letter/a/9f8e36/32.png) [@ameneh1986](https://community.postman.com/u/ameneh1986)\
**Post date:** [September 24, 2024, 9:47am UTC](https://community.postman.com/t/unable-to-read-pre-request-script-while-running-postman-cli/68769/5 "2024-09-24T09:47:24Z")

</div>

Hi @danny-dainton  
Not sure it is the thing that you are looking oe not:

Postman CLI command preview

stages:

- automated-api-tests

automated-api-tests:

stage: automated-api-tests

image: cimg/base: 2021.04 before\_script:

# Installing Postman CLI

- curl -o- “[https://dl-cli.pstmn.io/install/linux64.sh](https://dl-cli.pstmn.io/install/linux64.sh)” | sh script:

# Login using your Postman API keys

- postman login --with-api-key $POSTMAN\_API\_KEY
- postman collection run “28067525-e1f57cd4-e870-489d-9460-4d56a855f60d” - e  
“28067525-b81a2f68-852b-4d14-890e-5c73436cba39”

---

<div class="post-metadata">

**Author:** ![ameneh1986](https://avatars.discourse-cdn.com/v4/letter/a/9f8e36/32.png) [@ameneh1986](https://community.postman.com/u/ameneh1986)\
**Post date:** [September 25, 2024, 10:24am UTC](https://community.postman.com/t/unable-to-read-pre-request-script-while-running-postman-cli/68769/6 "2024-09-25T10:24:31Z")

</div>

Dear @danny-dainton  
I also tried with latest image and still it is failing

```auto
automated-api-tests:
  stage: post-development-tests
  image: cimg/base:2024.09
  before_script:
    - curl -o- "https://dl-cli.pstmn.io/install/linux64.sh" | sh
  script:
    - postman login --with-api-key $POSTMAN_API_KEY
    - postman collection run 28067525-e1f57cd4-e870-489d-9460-4d56a855f60d -e 28067525-b81a2f68-852b-4d14-890e-5c73436cba39
  artifacts:
    paths:
      - automated-api-tests-status.txt
  only:
    - develop
  tags:
    - aks-test01
  allow_failure: true
  when: delayed
  start_in: 5 minutes

```

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [September 25, 2024, 11:42am UTC](https://community.postman.com/t/unable-to-read-pre-request-script-while-running-postman-cli/68769/7 "2024-09-25T11:42:42Z")

</div>

Taking a look at this now and I’ve raised this with the team - I will update the thread if I have anymore information.

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [September 25, 2024, 4:10pm UTC](https://community.postman.com/t/unable-to-read-pre-request-script-while-running-postman-cli/68769/8 "2024-09-25T16:10:52Z")

</div>

Hey @ameneh1986

Were not able to reproduce this on our side using your script.

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/5/6/5646526ba632b6609a6ad276bc5f493f0e4ebc2c.png)

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/4/8/4853f781f86ace9262293a4a6dc4bd4246957cf7.jpeg)

As you can see it’s resolved the variable from the pre-request scripts that that executed during the run.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/system/32/29796_2.png) [@system](https://community.postman.com/u/system)\
**Post date:** [October 25, 2024, 4:11pm UTC](https://community.postman.com/t/unable-to-read-pre-request-script-while-running-postman-cli/68769/9 "2024-10-25T16:11:08Z")

</div>

Closed on October 25, 2024, 4:11pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
