# PropertyList is not defined in pre-request script

**URL:** <https://community.postman.com/t/propertylist-is-not-defined-in-pre-request-script/51239>\
**Category:** Help Hub\
**Tags:** pre-request-script, request-body\
**Created:** [August 31, 2023, 8:54pm UTC](https://community.postman.com/t/propertylist-is-not-defined-in-pre-request-script/51239 "2023-08-31T20:54:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ataul](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/ataul/32/25547_2.png) [@ataul](https://community.postman.com/u/ataul)\
**Post date:** [August 31, 2023, 8:54pm UTC](https://community.postman.com/t/propertylist-is-not-defined-in-pre-request-script/51239/1 "2023-08-31T20:54:11Z")

</div>

Hi folks, I’m trying to emulate the behavior of [Ruby’s encode\_www\_form](https://apidock.com/ruby/URI/encode_www_form/class) in a pre-release script. (If there’s a quick way to do this, I’d appreciate that, but otherwise, this is the issue I’m currently facing:)

`pm.request.body.urlencoded` is a [PropertyList](https://www.postmanlabs.com/postman-collection/PropertyList.html). It even says so in Postman when I hover over it.

When I try any methods on it (e.g. `map`) it says that `PropertyList` is not defined. Do I need to import it somehow? Here is a public workspace showing the issue:

[https://www.postman.com/ataulmunim/workspace/ataul-s-public-workspace/request/3802821-9bc519e6-3792-45e9-b35d-6b0a7a36326f?ctx=documentation](https://www.postman.com/ataulmunim/workspace/ataul-s-public-workspace/request/3802821-9bc519e6-3792-45e9-b35d-6b0a7a36326f?ctx=documentation)

I’ve tried it on the web and also on the OS X native app (Apple silicon).

---

<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:** [August 31, 2023, 10:22pm UTC](https://community.postman.com/t/propertylist-is-not-defined-in-pre-request-script/51239/2 "2023-08-31T22:22:49Z")

</div>

Hey @ataul 👋

Welcome to the Postman Community! :postman:

I’m not sure what your use case is or what you’re trying to achieve but you’d need to use this at the top of the script, to make that work:

```auto
PropertyList = require('postman-collection').PropertyList

```

The `postman-collection` is an external module that’s part of the scripts sandbox:

> **[Postman Sandbox API | Postman Learning Center](https://learning.postman.com/docs/sending-requests/grpc/postman-sandbox-api/#using-external-libraries)**
>
> Postman Sandbox API: documentation for Postman, the collaboration platform for API development. Create better APIs—faster.

---

<div class="post-metadata">

**Author:** ![ataul](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/ataul/32/25547_2.png) [@ataul](https://community.postman.com/u/ataul)\
**Post date:** [September 1, 2023, 7:21am UTC](https://community.postman.com/t/propertylist-is-not-defined-in-pre-request-script/51239/3 "2023-09-01T07:21:55Z")

</div>

> [@danny-dainton](#):
>
> ```auto
> PropertyList = require('postman-collection').PropertyList
> 
> ```

Thanks Danny, this works! Is the dot notation after the `require` something that’s Postman-specific or is this a common language feature?

> [@danny-dainton](#):
>
> ```auto
> I’m not sure what your use case is or what you’re trying to achieve...
> 
> ```

At the moment, I’m trying to URI encode the keys/values from a form body and join them back up with `&`. When I used `encodeURI` or `encodeURIComponent`, it also transformed the `&` which wasn’t what I needed. Accessing the property list means I can map the entries into the format I need:

```auto
// for key: "password", value: "at_next_@_and_next_&"

PropertyList = require('postman-collection').PropertyList
console.log(pm.request.body.urlencoded.toString())
console.log(pm.request.body.urlencoded.map(encode).join('&'))

function encode(entry) {
    return `${encodeURIComponent(entry.key)}=${encodeURIComponent(entry.value)}`
}

// "password=at_next_@_and_next_%26"
// "password=at_next_%40_and_next_%26"

```

---

<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 1, 2023, 9:13am UTC](https://community.postman.com/t/propertylist-is-not-defined-in-pre-request-script/51239/4 "2023-09-01T09:13:38Z")

</div>

It’s a common language feature and it allows you to access a function inside the object. I’m not even going to pretend like I know this topic inside out, I really don’t but I know you _can_ do that. 😬

In terms of the Postman Sandbox, if you remove the `.PropertyList` and then added a `.` again, you’d be shown the other functions.

 ![Screenshot 2023-09-01 at 10.00.08](https://us1.discourse-cdn.com/getpostman/original/3X/f/3/f3ccf7d11b4b331b5d6c2f9533814de62f7d4fc2.png)

---

<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:** [September 4, 2023, 9:14am UTC](https://community.postman.com/t/propertylist-is-not-defined-in-pre-request-script/51239/5 "2023-09-04T09:14:33Z")

</div>

Closed on September 4, 2023, 9:14am UTC

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