How to pass boolean values using Postman?

Using Postman, I passed boolean value, But I got error.
The value which I pass to server through Postman is not a boolean value.

I just input True in value form.
is it wrong?

How to pass boolean value?

It is unclear from your question how exactly you are ending the data, but this will not matter a lot.

Regardless of the format (query params, JSON body) it is the job of the backend to parse and validate the request.

So even if you send a parameter like “active=true”, it is still a string, this is how the HTTP protocol works.

Hope this helps clarify the mystery.

1 Like

Hi Nelson

You can parse the string as boolean data type as below -

var bflag = Boolean(“true”);
var bflag1 = Boolean(“false”);

Let me know if it works or not!

I mean using Postman how to pass boolean values. You wrote js code, right?

So, there is no way to pass boolean value to server using Postman? because through the HTTP protocol just string-formatted data passed?

Then I have to do format data on server?

Hi there,

I’m trying to randomize a true/false boolean value, which I want to assign to a variable that I can then pass to my Body and post as part of my JSON. I tried this:

var arrayCert = [true, false];
pm.globals.set('certVal',  arrayCert[Math.floor(Math.random()*arrayCert.length)]);

Which does get me a random variable in certVal . But when I try to pass that variable in my Body like so:

"Certified": "{{certVal}}",

I get this message:

"INVALID_REQUEST_PARAMETER: 'Certified' Expected type boolean but found type string; ",

I think the double quotes in the body is passing the variable as a string, hence the error. If I change it to:

"Certified": true,

Then the post works as expected. Is there anyway I can pass a random boolean in this way?

Thanks so much for any help.

Ed

@ed_truqc Variable references of the form {{var_name}} are resolved literally within all parts of a request, so the following will work:

"Certified": {{certVal}},

As there are no enclosing quotes around {{certVal}}, it will be resolved to true/false, which will get your requests working regularly :smile:

1 Like

you can use 1 instead of true and 0 instead of false. And convert it to bool values within your backend.

it works, thank you!

Sorry to say, I didn’t get it properly…

Hey @descent-module-obs19 :wave:

Welcome to the Postman community :postman:

As you’re responding to a topic over 10 months after the last post - can I ask that you raise a new topic with all of your details so that we can help with your specific issue.

I’m going to close this topic now.