Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mutating request body using pre-request script #2729

Closed
warhaemish opened this issue May 3, 2021 · 3 comments
Closed

Mutating request body using pre-request script #2729

warhaemish opened this issue May 3, 2021 · 3 comments

Comments

@warhaemish
Copy link

warhaemish commented May 3, 2021

Hi,
I am using pm.request.body.update() method in my pre-request script to modify the request body.
It is working fine in Postman but fails when using Newman (it doesn't modify the request).

Recently, in the Postman version 8.3.0 the functionality to mutate the request body in the pre-request script was added (postmanlabs/postman-app-support#4808).

My doubt is -

  • Whether this functionality is applicable to Newman currently and I'm missing something
  • or if it is currently not there and hopefully would be available at a later date.

Version and environment information:

  1. Newman Version (can be found via newman -v): 5.2.2

  2. OS details (type, version, and architecture): Windows 10, 64 Bit

  3. Are you using Newman as a library, or via the CLI? Using it via CLI

  4. Expected behaviour: The request should be modified when the pre-request script is executed. And the output should be similar to when the collection runs in Postman

  5. Command / script used to run Newman: newman run Newmanissue.postman_collection --insecure

  6. Sample collection, and auxiliary files (minus the sensitive details): https://www.postman.com/collections/27b5ee14bcb5c3d293c8

  7. Screenshots (if applicable):

When run using Postman -
image
image

When run using Newman
image

Steps to reproduce the problem:

  1. Import the collection in Postman
  2. Run the collection and note the response and console logs
  3. Run the same collection in Newman. The sent request is not modified when using Newman.
@codenirvana
Copy link
Member

@warhaemish Thanks for reporting this issue.

This is fixed in Newman v5.2.3.

@danielbsimoes
Copy link

Hi!
I'm using newman version 5.3.2 and apparently it is not possible to use pm.request.body.update() IF your body is set as none in postman.
This is the error I obtain
image
I was able to fix it by using the raw option (which then turns body into an empty string) - can this be fixed as well?

@AnechaS
Copy link

AnechaS commented Mar 30, 2023

Hi! I'm using newman version 5.3.2 and apparently it is not possible to use pm.request.body.update() IF your body is set as none in postman. This is the error I obtain image I was able to fix it by using the raw option (which then turns body into an empty string) - can this be fixed as well?

Try it

pm.request.body = '{}'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants