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

Cannot set request body programmatically #8466

Closed
StrohmyerTR opened this issue May 11, 2020 · 4 comments
Closed

Cannot set request body programmatically #8466

StrohmyerTR opened this issue May 11, 2020 · 4 comments

Comments

@StrohmyerTR
Copy link

Description
We can set the Postman object's URL and headers programmatically, but not its body.

Repro
Steps to reproduce the behavior:

  1. Open a new request tab
    a. Set the URL to "Test"
    b. Don't set any headers
    a. Set the body to "{}"

  2. In the pre-request script, reset the following Postman request object fields as such:
    a. pm.request.url.host = "https://postman-echo.com";
    b. pm.request.headers.add( { key: "test_key", value: "test_value" } );
    c. pm.request.body = { "data": [ "test_body" ] };

  3. Add a log statement to output the Postman request object to the console
    e.g. console.info(pm.request);

  4. Click "Send"

  5. Open the console, and compare the log.info output to the actual request sent by Postman.

Expected behavior
In both the log.info statement and the network log statement; the request URL is reset, the headers are appended, and the request body is reset.

Actual behavior
The log statement shows us that the request object is updated as expected (URL, headers, and body).

The actual request sent by Postman shows us that the URL is updated (good), the headers are updated (good), and the request body does not honor the programmatic update (bad).

It should be: { "data": [ "test_body" ] }

But, it is: {}

App information

  • Postman for Windows
  • 7.23.0
  • win32 10.0.18362 / x64

Additional context
This may be an enhancement request, but due to the nature of allowing dynamic/programmatic URL and header setting - it comes off as a bug.

Please reach out if you require additional information.

@StrohmyerTR
Copy link
Author

P.S. I am aware of the fact that I could set the request body (via the UI) to "{{example_variable}}", and set that variable's value programmatically.

I am developing a less technical/more user-friendly way for any person on my team to be able to send requests for a variety of internal endpoints, each of them having a unique workflow, and each also having a final request body which is not the same request body which is input into the UI's "Body" tab.

@codenirvana
Copy link
Member

Closing as duplicate of #4808

@jordanbisato
Copy link

jordanbisato commented Apr 16, 2021

It's possible to reopen this issue @codenirvana ?
I think it's a important funcionality to Postman.

@codenirvana
Copy link
Member

Postman v8.3.0 added support for programmatically mutating the request body.

Refer #4808 (comment) for more details.

This issue was closed.
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

3 participants