# Pm.request manipulation not working before the request is sent

**URL:** <https://community.postman.com/t/pm-request-manipulation-not-working-before-the-request-is-sent/62268>\
**Category:** Help Hub\
**Tags:** authorization, request, pre-request-script\
**Created:** [June 16, 2024, 2:31pm UTC](https://community.postman.com/t/pm-request-manipulation-not-working-before-the-request-is-sent/62268 "2024-06-16T14:31:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rustnnespp](https://avatars.discourse-cdn.com/v4/letter/r/f14d63/32.png) [@rustnnespp](https://community.postman.com/u/rustnnespp)\
**Post date:** [June 16, 2024, 2:31pm UTC](https://community.postman.com/t/pm-request-manipulation-not-working-before-the-request-is-sent/62268/1 "2024-06-16T14:31:03Z")

</div>

Hi, Postman Community!

Is it possible to use the `pm.request.auth` property or the `pm.request.authorizeUsing()` function, so I can handle authorization for requests in a pre-request script?

I tried to set the property like the following:

```js
// either this object
const authz = {
  type: 'bearer',
  bearer: [
    {
      type: 'any',
      value: [
        {
          type: 'any',
          value: 'token value',
          key: 'token',
        },
      ],
      key: 'bearer',
    },
  ],
};

// or this another object
const authz = {
  type: 'bearer',
  bearer: [
    {
      type: 'any',
      value: 'token value',
      key: 'token',
    },
  ],
};

// either this way
pm.request.auth = authz;

// either this another way
pm.request.authorizeUsing(authz);

```

but none of them worked.

For the next examples, I had to setup the request Auth tab with type Bearer and a token generated previously, as I could not get the examples above to work.

Debugging the request, seems like I can only access and manipulate the `auth` property and the Authorization header **after** the request is sent.

The pre-request script for the request is:

```js
// stage 1: the initial state of the request
console.log("request before")
console.log(pm.request.toJSON())

// stage 2: removing auth header and auth property
// from the request
pm.request.removeHeader('Authorization')
pm.request.auth = null

// stage 3: request after change; same result,
// except for the new property auth
console.log("request after")
console.log(pm.request.toJSON())

```

The post-response script for the request is:

```js
// stage 4: request was sent already;
// but auth header is present and auth property is defined
console.log("response before")
console.log(pm.request.toJSON())

// stage 5: removing auth header and auth property
// again from the request
pm.request.removeHeader('Authorization')
pm.request.auth = null

// stage 6: auth header removed and auth property null
console.log("response after")
console.log(pm.request.toJSON())

```

The results for the scripts above is showed in the image below.

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/c/9/c9a4ffb01116ef94d0f62b8f099e2db3ac6cee6b.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:** [July 16, 2024, 2:31pm UTC](https://community.postman.com/t/pm-request-manipulation-not-working-before-the-request-is-sent/62268/2 "2024-07-16T14:31:42Z")

</div>

Closed on July 16, 2024, 2:31pm UTC

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