Skip to main content
1-Visitor
July 8, 2016
Question

thingworx api 401

  • July 8, 2016
  • 3 replies
  • 3025 views

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.

3 replies

1-Visitor
July 8, 2016

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.
5-Regular Member
July 8, 2016

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

dsergio1-VisitorAuthor
1-Visitor
July 14, 2016

The first.

dsergio1-VisitorAuthor
1-Visitor
July 14, 2016

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

Thanks.

5-Regular Member
July 14, 2016

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