# Receive error message Pre-request Script ... (reading 'lengt

**URL:** <https://community.postman.com/t/receive-error-message-pre-request-script-reading-lengt/57788>\
**Category:** Help Hub\
**Tags:** tests, variables\
**Created:** [February 18, 2024, 8:59pm UTC](https://community.postman.com/t/receive-error-message-pre-request-script-reading-lengt/57788 "2024-02-18T20:59:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![flight-operator-3342](https://avatars.discourse-cdn.com/v4/letter/f/a88e57/32.png) [@flight-operator-3342](https://community.postman.com/u/flight-operator-3342)\
**Post date:** [February 18, 2024, 8:59pm UTC](https://community.postman.com/t/receive-error-message-pre-request-script-reading-lengt/57788/1 "2024-02-18T20:59:59Z")

</div>

Hi all,

Apologies I’m very new to postman. This is either a bug or i’m missing something very obvious.

I use a curl command on linux to remotely get instance status and to start and stop an oracle cloud (oci) instance (VM).

I am trying to do the same using postman.

I have followed the instructions on the below link  
[Invoking Oracle OCI REST APIs using Postman to Start/Stop the instance](https://www.linkedin.com/pulse/invoking-oracle-oci-rest-apis-using-postman-startstop-shirbhate/) as well as many many other websites.

While I can Get instance information proving that the authentication is working correctly when I try and send POST request to start and stop the instance I get the below error message.

_There was an error in evaluating the Pre-request Script:TypeError: Cannot read properties of undefined (reading ‘length’)._

The environment settings are the attached, There is a length field which i have tried populating, I have also tried removing it but the error message stays the same

 ![Screenshot 2024-02-18 204521](https://us1.discourse-cdn.com/getpostman/original/3X/7/3/736e23ce35215561b61f8a3af305ecccb4292034.jpeg)

Headers with errrors

 ![Screenshot 2024-02-18 205726](https://us1.discourse-cdn.com/getpostman/original/3X/9/6/96c340be74f38fa5d2770156da81ed5bfe1cc8b6.jpeg)  
\

Can someone point me in the right direction? I have search postman forums, oracle support website and also google but no luck.

Thanks

Regards

Ed

---

<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:** [February 18, 2024, 9:16pm UTC](https://community.postman.com/t/receive-error-message-pre-request-script-reading-lengt/57788/2 "2024-02-18T21:16:54Z")

</div>

Hey @flight-operator-3342 👋

Welcome to the Postman community :postman:

As your request screenshot doesn’t show anything in the pre-request script, I can only assume that it’s something at the Collection level.

If you click on the Collection name in the breadcrumb above the URL bar. That should open the Collection in a new tab.

Does that contain anything in the pre-request tab?

---

<div class="post-metadata">

**Author:** ![flight-operator-3342](https://avatars.discourse-cdn.com/v4/letter/f/a88e57/32.png) [@flight-operator-3342](https://community.postman.com/u/flight-operator-3342)\
**Post date:** [February 18, 2024, 9:41pm UTC](https://community.postman.com/t/receive-error-message-pre-request-script-reading-lengt/57788/3 "2024-02-18T21:41:00Z")

</div>

Hi Danny,

There was an entry in the Pre-request Script of the parent collection.

I changed

```auto
var body = "";

if(methodsThatRequireExtraHeaders.indexOf(request.method.toUpperCase()) !== -1) {
    body = pm.request.body.raw;
    //pm.environment.set("length", body.length);
   var content_length_header = "content-length: "+ body.length ;
}

```

to

```auto
var body = "";

if (methodsThatRequireExtraHeaders.indexOf(request.method.toUpperCase()) !== -1) {
    if (pm.request.body && pm.request.body.raw) {
        body = pm.request.body.raw;
    }
var content_length_header = "content-length: " + body.length;

```

And now the start and stop works correctly.

I am unsure how this worked for other people but with the update it now works for me.

Thanks.

Ed

---

<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:** [February 21, 2024, 9:41pm UTC](https://community.postman.com/t/receive-error-message-pre-request-script-reading-lengt/57788/4 "2024-02-21T21:41:45Z")

</div>

Closed on February 21, 2024, 9:41pm UTC

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