Set request body dynamically
Number of APIs: 1
- Build the body in the form of a JSON object. This happens inside the pre-request script.
js var body = { id: 'asdas', pwd: 'asdas', auth: 'ashd' }; - Stringify the body, using JSON.stringify. This converts objects to strings.
js var body_str = JSON.stringify(body); // body was defined in the previous step. Save the stringified body as an environment variable using
pm.environment.set;js pm.environment.set('request_body', body_str); // this sets an environment variable with the stringified bodyIn the request body editor, specify the
rawrequest body as the variable created in step 3.{{request_body}}
Note that the snippet from step 4 will have to be placed in the body editor.