3 Replies Latest reply on Feb 8, 2017 2:22 PM by polinao RSS
    sbandaru 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.

      • Re: Process HTTP Requests
        supandey Collaborator

        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.

        • Re: Process HTTP Requests
          jkaczynski-2 Creator

          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[s]://<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.

          • Re: Process HTTP Requests
            polinao Ninja

            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.