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 value 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?
as far as i know
Boolean values weren’t denoted with double quotes.
if the Boolean value is double quoted, it is considered as string. (same happened in your case).
@gopikrishna4595, thanks for your response. I have tried this, and it appears to be working when the value is true. But if the value if false, I get this error:
expected '{"error_msg":"Unexpected token , in JSON at position 109","error_debug":"DEBUG: ","error_type":""}'
Any idea why false alone would cause this error?
I can actually see that when certVal is set to true, it gets passed as true:
\"Certified\": true,\n
but when certVal is set to false, it gets passed as a blank:
@gopikrishna4595 . It used to work but now it’s getting an error. I’ll check with my devs as there may be something wrong with our api.
Gaaah, sorry for all the edits. So if I manually set Certified to false, the post works correctly. If I change my array to false only, rather than true and false, then certVal is set to false, but Certified is set to blank:
@gopikrishna4595 Just re-read your post. Sorry for the confusion. I just tried setting certVal as an environment variable, set to false, and that worked!
I think I may have a problem with my api, as I’m seeing inconsistent results. Sometimes the post passes and sometimes it fails. I’ll investigate further on my end, but this does appear to be working now. Thanks again so much for your help and patience!