Creating a request with raw json body

I am trying to create a request inside a new/update collection API call, having the equivalent of the raw - json body inside the client.

Right now, it seems like I need to send something like (I am using ruby, but it shouldn’t make a big different):

body: {
  mode: 'raw',
  json: {
    field1: 'value',
    field2: 'value2'
  }
}

I want to avoid using 'formdata', because I already have the hash and parsing it into formdata format would add extra complexity (especially because I have to handle multiple nests).

When using this, I get a 200, but the generated request has an empty body.

I’ve also tried using mode: raw, text: {}, but same result. Also, I’ve tried

body: {
  json: { field: 'value' }             
}

and

body: { field: 'value' }

and it didn’t work.

Is there any way to make this work? Also, didn’t find any examples of how to send the body in the docs.

1 Like

@Victor_Motogna Welcome to the Community :partying_face:

You can try something like

var body = {
    "field1" : "value",
    "field2" : "value2"
  };

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

Please refer this link for examples :innocent:

4 Likes

That worked great, thanks!

2 Likes

Hi All,

How can I send json object in raw mode without stringify-ing it?
I have type error from backend which is not a custom error ,but an error from library when sending payload in pre-script using:
body: {
mode: ‘raw’,
raw: JSON.stringify({
“key”: “value”
});
}
{“detail”:[{“loc”:[“body”],“msg”:“value is not a valid dict”,“type”:“type_error.dict”}]}

OK I found the solution:
We need to add a header with
content-type: application/json
))