I just started working with postman and wanted to see if I could get some help with constructing the POST request body.
My sample request body (JSON) is
As I understand we’d need to escape the special characters in HTML_STRING. What would be the best way to achieve loading the html content from file and having it as a part of the request as shown above, in Postman? Do I need to get the escaped content with some external script/online tool first before I formulate the request and then POST to my API ?
Hello @4rk, Welcome to the community
There are two options:
- If you are writing an external script for creating a file, I would suggest escaping the special characters and then putting the HTML content in the file.
- you can use postman’s pre-request script for escaping the special characters in HTML content.
To use the HTML content as a part of API request:
- Create a data file with id and data
- Iterate the file and access the value from the file using
- Set the environment/global/collection variable after getting data from file.
- Use Dynamic variable for assign value within JSON body.
I hope this works for you.
Here the data, unless is escaped in the json/csv, does not seem valid. Doesn’t that necessitate that extra step to escape the data content first? Also, another example of the content I might send, on a different endpoint, is an email (headers with plain/html content), so not exactly just HTML. My apologies, if that would change the context and content of your original answer. I thought they could be handled in the same fashion.