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

Community Tip - You can subscribe to a forum, label or individual post and receive email notifications when someone posts a new topic or reply. Learn more! X

Process HTTP Requests

sbandaru
1-Newbie

Process HTTP Requests

Hi, I need a service in Thingworx for receiving Http GET/Post requests and process it.  How could I achieve this.

1 ACCEPTED SOLUTION

Accepted Solutions
jkaczynski
4-Participant
(To:sbandaru)

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.

View solution in original post

3 REPLIES 3
supandey
19-Tanzanite
(To:sbandaru)

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 :

  1. REST API Overview and Examples
  2. ThingWorx REST API Cheat Sheet

Hope this would help.

jkaczynski
4-Participant
(To:sbandaru)

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.

posipova
20-Turquoise
(To:sbandaru)

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.

Top Tags