How to send Gzip Compressed request using pre request script

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 ?

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.

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.

it says that " The data in the request body - . This object is immutable and can’t be modified from scripts:" source
I would like to change the body before sending from UI, is this not possible ?

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!

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