5 Replies Latest reply on Jul 14, 2016 10:03 AM by meghan RSS
    dsergio Newbie

    thingworx api 401

    hi, i have an authentication problem with the rest api.

    I made the same http request with postman and i have two possible response (200 or 401).

    How this is possible?


    This is the tomcat access log:

    10.0.0.61 - - [07/Jul/2016:14:39:00 +0200] POST /Thingworx/Things/prova/Services/getData?data=hello&appKey=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx HTTP/1.1" 401 1192

    10.0.0.61 - - [07/Jul/2016:14:39:01 +0200] POST /Thingworx/Things/prova/Services/getData?data=hello&appKey=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx HTTP/1.1" 200 167

     

    Thank you.

      • Re: thingworx api 401
        carlesc Ninja

        The TW Authentication process it's a bit weird...

         

        Few things:

        • You should pass as header:
          • Content-Type: application/json
          • Accept: application/json
          • x-thingworx-session: true
          • appKey: yourAppKey
        • If you are doing a logout, better you call it twice, this way it removes the cookie too, otherwise it doesn't removes the cookie and it fails the next time you try to login.
        • Re: thingworx api 401
          ttielebein Collaborator

          Hello,

           

          Are you saying you see one or the other of those two responses per each request, or that somehow two responses are coming back to you?

           

          Is the HTTP/1.1 a part of the request?

           

          Thanks!

          Tori

          • Re: thingworx api 401
            dsergio Newbie

            After restarting tomcat all works, but I don't understand what the problem was.

            Thanks.

              • Re: thingworx api 401
                meghan Communicator

                Even when logging into the browser the authentication dialog box pops up twice, typically, prompting for authentication when there are no active sessions for that user. I'm not entirely sure why that occurs, but that is consistent with the behavior you are seeing when sending that initial REST request as well. I've submitted a JIRA to R&D regarding this issue and this article will be used to update the status of that JIRA.

                 

                Meghan