How to add Actual request body in pre-request script without using environment variable

Hey @apakhare

Welcome to the community! :trophy:

If I understand you correctly, I think something like this should work:

const options = {
    url: "https://postman-echo.com/post",
    method: 'POST',
    header: { 'content-type': 'application/json' },
    body: {
        mode: 'raw',
        raw: JSON.stringify({ "Id": "1255", "URL": "https://localhost/4455", "cId": `Case${pm.environment.get("RANDOMOBCID")}`, "cuList": [{ "cuId": `${pm.environment.get("RANDOMOBCID")}` }] })

    }
};

pm.sendRequest(options, function (err, res) {
    var jsonData = res.json();
    if (err) {
        console.log(err);
    }
    else {
        pm.environment.set("Response", jsonData.ID);
    }
});

I’ve just used the Postman-Echo service to post the request but you can replace the URL with your own and give it a go.

3 Likes