Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X
Hi, I need a service in Thingworx for receiving Http GET/Post requests and process it. How could I achieve this.
Solved! Go to Solution.
Hi Shankar Bandaru,
tl;dr
Every characteristic of Entity in Thingworx (Service, Property etc.) can be reached using REST calls. So if you'd like to create a service that receives a HTTP call you need to create a normal service. Beware: you can reach the services only using requests of type POST!
The input parameters of the service conforms to the body parameter of the request. So if your service have two parameters: name (STRING) and age (NUMBER), the body of your request should looks like below:
{
"name": "MyName",
"age": 1
}
The request should have ApplicationKey with permissions to invoke your service (better choice) or Userid and Password (worse choice).
Additionally, you can use headers: Content-Type: application/json and Accept: application/json.
The endpoind you should reach should follow the pattern:
http://<host>:<port>/Thingworx/<EntityType>/<EntityName>/Services/<ServiceName>
e.g.
http://localhost:8080/Thingworx/Things/MyThing/Services/MyService
If you use headers mentioned above and your service returns anything, it would be in the format of JSON (can set this baseType also on the service, if necessary).
Hope it helps. For more info, you should reach to the official REST API guides.
Regards,
J.
Hi Shankar, are you referring to storing and processing the data which you plan to push to ThingWorx using REST API? I think this is quite extensively covered on ThingWorx community, here are some of the blogs I can list quickly for you to get started :
Hope this would help.
Hi Shankar Bandaru,
tl;dr
Every characteristic of Entity in Thingworx (Service, Property etc.) can be reached using REST calls. So if you'd like to create a service that receives a HTTP call you need to create a normal service. Beware: you can reach the services only using requests of type POST!
The input parameters of the service conforms to the body parameter of the request. So if your service have two parameters: name (STRING) and age (NUMBER), the body of your request should looks like below:
{
"name": "MyName",
"age": 1
}
The request should have ApplicationKey with permissions to invoke your service (better choice) or Userid and Password (worse choice).
Additionally, you can use headers: Content-Type: application/json and Accept: application/json.
The endpoind you should reach should follow the pattern:
http://<host>:<port>/Thingworx/<EntityType>/<EntityName>/Services/<ServiceName>
e.g.
http://localhost:8080/Thingworx/Things/MyThing/Services/MyService
If you use headers mentioned above and your service returns anything, it would be in the format of JSON (can set this baseType also on the service, if necessary).
Hope it helps. For more info, you should reach to the official REST API guides.
Regards,
J.
To add to everything posted above - another good reference for constructing your REST calls is your browser Developer tools. For example, in chrome you can open by clicking ctrl+shift+i, then navigate to the "console" and then you can see the calls' structure.