Skip to main content
Sep 18, 2017 4:33 PM UTC
Solved

Random value output using Postman

         Hi, I am trying to generate an output as a random number using Postman and I want to PUT this output value onto thing as a thing property value but

As in the official Mars Rover example used in the academic course, to change the 'WindSpeed' property using postman, the following syntax was used:

{

"WindSpeed" : "88"

}

But now I want to pass on the value of the "WindSpeed" in an automated manner (something like using the random value function) so that I don't have to manually change it every time,

Unfortunately, I am not able to do so as I have trying ways available online including setting global variables etc. etc. but it is always giving an error of 'BAD STRING' or that the JSON content does not have 'ValidProperties' etc. I think that maybe my syntax is wrong. Could someone please guide me as to how we can generate random values in postman(syntax etc.) and PUT it onto the thing so that it updates itself.


Thanks!

ytellaAnswer
Sep 21, 2017 5:43 PM UTC

Hi Tushar Yadav,

Please try the below alternative method to set a random number for a property:

  • Create a service to set the random value for a property as shown below:

    

    

  • If you see the HTTP status code as 200 then the request is successful.
  • To verify if the random value is assigned to the property, Open ThingWorx composer, click on the Thing-->Properties-->Refresh value

     

5 replies

Sep 18, 2017 5:49 PM UTC

Hi Tushar Yadav,

Have you tried the below format?

var x = Math.floor((Math.random() * 100));

WindSpeed : x


tyadavAuthor
Sep 18, 2017 9:19 PM UTC

Hi Yamini,

Yes, I did try it like this but it shows error. I am attaching the screenshot for your reference.

postman_1.png

ytellaAnswer
Sep 21, 2017 5:43 PM UTC

Hi Tushar Yadav,

Please try the below alternative method to set a random number for a property:

  • Create a service to set the random value for a property as shown below:

    

    

  • If you see the HTTP status code as 200 then the request is successful.
  • To verify if the random value is assigned to the property, Open ThingWorx composer, click on the Thing-->Properties-->Refresh value