-
Notifications
You must be signed in to change notification settings - Fork 839
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
Comments
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. |
Closing as duplicate of #4808 |
It's possible to reopen this issue @codenirvana ? |
Postman v8.3.0 added support for programmatically mutating the request body. Refer #4808 (comment) for more details. |
Description
We can set the Postman object's URL and headers programmatically, but not its body.
Repro
Steps to reproduce the behavior:
Open a new request tab
a. Set the URL to "Test"
b. Don't set any headers
a. Set the body to "{}"
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" ] };
Add a log statement to output the Postman request object to the console
e.g. console.info(pm.request);
Click "Send"
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
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.
The text was updated successfully, but these errors were encountered: