Body Drops When Sending POST Request in Script

I’m trying to send a request in a pre-request script:

var reqParams = {
    url: 'localhost:8090/my-app',
    method: "POST",
    header: {
       "Content-Type": "application/json",
    body: {
    	"key": { ... }
pm.sendRequest(reqParams, function (err, response) { ... });

In the console I see the request is sent but has no body, Content-Length header is ""

Is this a known issue in any way? Any suggestions?

Hi @jnfSmile

You’ll need to use the correct syntax for the body property:

 body: {
      mode: 'raw',
      raw: JSON.stringify({object})

Thanks @abhijit

is it possible to give mode: json?

@jnfSmile, not according to the Postman SDK docs.

My general approach to performing scripted requests is to:

  1. create a working request in GUI,
  2. console.log(pm.request),
  3. replicate logged data structure in script

Currently I have a problem with preparing a urlencoded request body for a ‘GUI’ request in its pre-request script. After updating it, it can be read and logged by console.log but the new body is not sent over the network when clicking the interactive Send button. A bit confusing.

Guess I didn’t get that when I looked in the docs. Thanks!