cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X

Random value output using Postman

tyadav
1-Newbie

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!

1 ACCEPTED SOLUTION

Accepted Solutions
ytella
17-Peridot
(To:tyadav)

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

     

View solution in original post

5 REPLIES 5
ytella
17-Peridot
(To:tyadav)

Hi Tushar Yadav,

Have you tried the below format?

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

WindSpeed : x


tyadav
1-Newbie
(To:ytella)

Hi Yamini,

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

postman_1.png

ytella
17-Peridot
(To:tyadav)

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

     

tyadav
1-Newbie
(To:ytella)

Hi Yamini,

Yes, this works.

Thanks for the solution!

ytella
17-Peridot
(To:tyadav)

Hi Tushar Yadav,


Glad to know that it helped!

Top Tags