# How to send Gzip Compressed request using pre request script

**URL:** <https://community.postman.com/t/how-to-send-gzip-compressed-request-using-pre-request-script/50676>\
**Category:** Help Hub\
**Created:** [August 17, 2023, 11:33am UTC](https://community.postman.com/t/how-to-send-gzip-compressed-request-using-pre-request-script/50676 "2023-08-17T11:33:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jaybhanushali](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/jaybhanushali/32/16495_2.png) [@jaybhanushali](https://community.postman.com/u/jaybhanushali)\
**Post date:** [August 17, 2023, 11:33am UTC](https://community.postman.com/t/how-to-send-gzip-compressed-request-using-pre-request-script/50676/1 "2023-08-17T11:33:10Z")

</div>

Hello,  
I have a request in JSON form, I would like to post that json in gzip compressed format to the endpoint that I have on UI,  
Is it possible to do that ?

---

<div class="post-metadata">

**Author:** ![kevinc-postman](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/kevinc-postman/32/12774_2.png) [@kevinc-postman](https://community.postman.com/u/kevinc-postman)\
**Post date:** [August 17, 2023, 9:16pm UTC](https://community.postman.com/t/how-to-send-gzip-compressed-request-using-pre-request-script/50676/2 "2023-08-17T21:16:15Z")

</div>

Hey @jaybhanushali !

While Postman does not support external Node.js libraries like `zlib` directly in its scripting environment, you can try [importing it a different way](https://blog.postman.com/adding-external-libraries-in-postman/).

If that doesn’t work, you might consider turning to Newman or the Postman CLI. With Newman, you can integrate Postman collections into scripts and automation pipelines, allowing you to use Node.js and its libraries, including `zlib`, more flexibly. You could:

1. Create a Node.js script that uses `zlib` to compress your JSON payload.
2. Use this script to store the compressed payload in an environment variable or a temporary file.
3. Trigger your Postman collection using Newman, referencing the stored compressed payload.
4. Ensure you set the `Content-Encoding: gzip` header in your request.

This way, you can automate the compression and request sending processes, taking advantage of the rich Node.js ecosystem alongside Newman.

I hope that helps! Let us know if you have any further questions.

---

<div class="post-metadata">

**Author:** ![jaybhanushali](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/jaybhanushali/32/16495_2.png) [@jaybhanushali](https://community.postman.com/u/jaybhanushali)\
**Post date:** [August 19, 2023, 1:30am UTC](https://community.postman.com/t/how-to-send-gzip-compressed-request-using-pre-request-script/50676/3 "2023-08-19T01:30:52Z")

</div>

it says that " The data in the [request body](https://www.postmanlabs.com/postman-collection/RequestBody.html) - . This object is immutable and can’t be modified from scripts:" [source](https://learning.postman.com/docs/writing-scripts/script-references/postman-sandbox-api-reference/#:~:text=the%20data%20in%20the%20request%20body.%20this%20object%20is%20immutable%20and%20can't%20be%20modified%20from%20scripts%3A)  
I would like to change the body before sending from UI, is this not possible ?

---

<div class="post-metadata">

**Author:** ![kevinc-postman](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/kevinc-postman/32/12774_2.png) [@kevinc-postman](https://community.postman.com/u/kevinc-postman)\
**Post date:** [August 21, 2023, 8:54pm UTC](https://community.postman.com/t/how-to-send-gzip-compressed-request-using-pre-request-script/50676/4 "2023-08-21T20:54:19Z")

</div>

You are correct; Postman doesn’t allow you to modify the request body through pre-request scripts. However, here’s a potential workaround:

1. Compress your JSON payload externally, converting the compressed content to a format like Base64.
2. Use this Base64 string as your request body in Postman.
3. On the server-side, decode the Base64 and decompress it to get your original payload.

If you need to integrate this process into an automated workflow, consider using Newman with Node.js, where you have more flexibility with libraries like zlib.

I hope this provides clarity!

---

<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:** [November 19, 2023, 8:54pm UTC](https://community.postman.com/t/how-to-send-gzip-compressed-request-using-pre-request-script/50676/5 "2023-11-19T20:54:45Z")

</div>

Closed on November 19, 2023, 8:54pm UTC

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