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

Community Tip - Need to share some code when posting a question or reply? Make sure to use the "Insert code sample" menu option. Learn more! X

How to fire two URL's at the same time?

sv
1-Newbie
1-Newbie

How to fire two URL's at the same time?

Hi,

I have two URL's.

     1. For PUT request

     2. For Firing the service// service URL is for assigning the values for all the properties in a thing.

Whenever i fire the put request, i have to fire the service URL also to take the effect. But i want it to be done together.How is that possible?

3 REPLIES 3
tcoufal
12-Amethyst
(To:sv)

Did you write those services by yourself? If yes I would suggest that, at the end of the PUT request service you(service itself) call the other service. Or you can join those two services into one.  

sv
1-Newbie
1-Newbie
(To:tcoufal)

Hi Tomas,

Yes i wrote that service. I want to know how that can be done? can you tell an example. I dint get you properly

tcoufal
12-Amethyst
(To:sv)

If you want to update the set of properties (not just one) that's how it's done:

Let's assume that you have a Thing:

<your_thing>

It has several properties:

prop1 [string]

prop2 [int]

prop3 [float]

..

By creating a real PUT request:

http://<your_machine>/Thingworx/Things/<your_thing>/Properties/*

with following headers:

appKey=<yourAppKey> (for testing purposes you should create one with Admin as user reference, not a good idea in a production scenario though)

Content-Type=applicate/json

with following body (raw):

{

    "prop1":"some_very_interesting_string",

    "prop2":45,

    "prop3":95.5

}


if you choose a Content-Type=text/xml

than your body must be as follows:

<Values>

     <prop1> awesome text </prop1>

     <prop2>2</prop2>

     <prop3>99.9</prop3>

</Values>


If you (or your App) cannot create a PUT request, than you need to append in URL '&method=put' in regular GET request, but you need to check

Allow request method switch in your PlatformSubsystem configuration (Platform will treat this GET request as it would be a PUT request). This will make you expose to risk of CSRF of coarse.


One note:

If you are creating a GET request you should send the values in URL - that is not recommended through several reasons, technically it is possible to pass data in Body even with GET request (HTTP 1.1), but HTTP handlers do not handle those data same way as they do with other requests.


rest - HTTP GET with request body - Stack Overflow

I hope you will find that useful.

If yes mark this answer as correct.

Tomas

Top Tags