<rss version="2.0" xmlns:a10="http://www.w3.org/2005/Atom"><channel><title>Inflectra Customer Forums: "Message: Authentification failed" when using REST with JSON (Thread)</title><description>&#xD;
&#xD;
&#xD;
&#xD;
&#xD;
&#xD;
Hello,  When I issue any REST request with Content-Type set to "application/json" in the HTTP header, I always get the following reply from the server:  {"Message":"Authentication failed.","StackTrace":"","ExceptionType":""}   Even with such a message, the request is processed without a problem.  I am testing this in Excel VBA. The following code should reproduce the issue. Please adjust carefully the value for your SpiraTeam configuration.  Public Sub ReproduceJSONContentTypeBug()     'Issue: When specifying JSON as Content-Type, the server replies     '{"Message":"Authentication failed.","StackTrace":"","ExceptionType":""}     Dim BASEURL As String     Dim PROJECT_ID As Long     Dim RESSOURCEURL As String     Dim USERNAME As String     Dim APIKEY As String     Dim requestBody As String     Dim MyRequest As Object          'Please adjust the following variables following your configuration     BASEURL = "http://XXXXX/SpiraTeam/Services/v4_0/RestService.svc/"     PROJECT_ID = XX     RESSOURCEURL = "projects/" &amp; PROJECT_ID &amp; "/incidents"     USERNAME = "XXXX"     APIKEY = "{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}"          'Please adjust ProjectId's value accordingly.     requestBody = "{""ProjectId"":XX,""Description"":""The server replied: 'Authentication failed.' but the incident was created."",""Name"":""Testing""}"      'HTTP request     Set MyRequest = CreateObject("WinHttp.WinHttpRequest.5.1")     MyRequest.Open "POST", BASEURL &amp; RESSOURCEURL     MyRequest.setRequestHeader "username", USERNAME     MyRequest.setRequestHeader "api-key", APIKEY     MyRequest.setRequestHeader "Content-Type", "application/json" 'THIS LINE TRIGGERS THE ERRONEOUS SERVER'S REPLY.     MyRequest.setRequestHeader "Accept", "application/json"     MyRequest.send (requestBody)          'The reply is always "{"Message":"Authentication failed.","StackTrace":"","ExceptionType":""}"     'But the command processed correctly.     Debug.Print MyRequest.responseText     MsgBox MyRequest.responseText End Sub &#xD;
&#xD;
&#xD;
&#xD;
&#xD;
&#xD;
&#xD;
&#xD;
&#xD;
&#xD;
&#xD;
&#xD;
</description><language>en-US</language><copyright>(C) Copyright 2006-2026 Inflectra Corporation.</copyright><managingEditor>support@inflectra.com</managingEditor><category domain="http://www.dmoz.org">/Computers/Software/Project_Management/</category><category domain="http://www.dmoz.org">/Computers/Software/Quality_Assurance/</category><generator>KronoDesk</generator><a10:contributor><a10:email>support@inflectra.com</a10:email></a10:contributor><a10:id>http://www.inflectra.com/kronodesk/forums/threads</a10:id><ttl>120</ttl><link>/Support/Forum/spirateam/issues-questions/863.aspx</link><item><guid isPermaLink="false">threadId=863</guid><author>Maxim Cournoyer (maxim.cournoyer@averna.com)</author><category domain="http://www.inflectra.com/kronodesk/thread/tag">rest</category><category domain="http://www.inflectra.com/kronodesk/thread/tag"> api</category><title>"Message: Authentification failed" when using REST with JSON</title><description>&#xD;
&#xD;
&#xD;
&#xD;
&#xD;
&#xD;
Hello,  When I issue any REST request with Content-Type set to "application/json" in the HTTP header, I always get the following reply from the server:  {"Message":"Authentication failed.","StackTrace":"","ExceptionType":""}   Even with such a message, the request is processed without a problem.  I am testing this in Excel VBA. The following code should reproduce the issue. Please adjust carefully the value for your SpiraTeam configuration.  Public Sub ReproduceJSONContentTypeBug()     'Issue: When specifying JSON as Content-Type, the server replies     '{"Message":"Authentication failed.","StackTrace":"","ExceptionType":""}     Dim BASEURL As String     Dim PROJECT_ID As Long     Dim RESSOURCEURL As String     Dim USERNAME As String     Dim APIKEY As String     Dim requestBody As String     Dim MyRequest As Object          'Please adjust the following variables following your configuration     BASEURL = "http://XXXXX/SpiraTeam/Services/v4_0/RestService.svc/"     PROJECT_ID = XX     RESSOURCEURL = "projects/" &amp; PROJECT_ID &amp; "/incidents"     USERNAME = "XXXX"     APIKEY = "{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}"          'Please adjust ProjectId's value accordingly.     requestBody = "{""ProjectId"":XX,""Description"":""The server replied: 'Authentication failed.' but the incident was created."",""Name"":""Testing""}"      'HTTP request     Set MyRequest = CreateObject("WinHttp.WinHttpRequest.5.1")     MyRequest.Open "POST", BASEURL &amp; RESSOURCEURL     MyRequest.setRequestHeader "username", USERNAME     MyRequest.setRequestHeader "api-key", APIKEY     MyRequest.setRequestHeader "Content-Type", "application/json" 'THIS LINE TRIGGERS THE ERRONEOUS SERVER'S REPLY.     MyRequest.setRequestHeader "Accept", "application/json"     MyRequest.send (requestBody)          'The reply is always "{"Message":"Authentication failed.","StackTrace":"","ExceptionType":""}"     'But the command processed correctly.     Debug.Print MyRequest.responseText     MsgBox MyRequest.responseText End Sub &#xD;
&#xD;
&#xD;
&#xD;
&#xD;
&#xD;
&#xD;
&#xD;
&#xD;
&#xD;
&#xD;
&#xD;
</description><pubDate>Thu, 20 Mar 2014 02:13:20 -0400</pubDate><a10:updated>2014-03-21T16:09:35-04:00</a10:updated><link>/Support/Forum/spirateam/issues-questions/863.aspx</link></item><item><guid isPermaLink="false">messageId=1572</guid><author>Jim R (donotreply5@kronodesk.net)</author><title>&#xD;
Hi Maxim if you leave the Content-Type alone and just send the Accept: application/json header, do</title><description>&#xD;
Hi Maxim if you leave the Content-Type alone and just send the Accept: application/json header, does it then work?  Regards  Jim &#xD;
&#xD;
</description><pubDate>Fri, 21 Mar 2014 14:50:23 -0400</pubDate><a10:updated>2014-03-21T14:50:23-04:00</a10:updated><link>/Support/Forum/spirateam/issues-questions/863.aspx#reply1572</link></item><item><guid isPermaLink="false">messageId=1575</guid><author>Maxim Cournoyer (maxim.cournoyer@averna.com)</author><title>&#xD;
Hi Jim, thank you for your answer.  Removing the Content-Type header didn't work because now the s</title><description>&#xD;
Hi Jim, thank you for your answer.  Removing the Content-Type header didn't work because now the server complained about the message being raw data.   However, the error gave me a hint by telling me that the accepted Content-Type are "Json" or "Xml" (notice the capitalized J). So I retried with      MyRequest.setRequestHeader "Content-Type", "application/Json"    and it worked without the authentication issue.  Seems like a bug that could be fixed by Inflectra. The error message should tell me exactly what is wrong, not some (inexistant) authentication problem.  This solves my question, thanks again! &#xD;
&#xD;
</description><pubDate>Fri, 21 Mar 2014 16:09:35 -0400</pubDate><a10:updated>2014-03-21T16:09:35-04:00</a10:updated><link>/Support/Forum/spirateam/issues-questions/863.aspx#reply1575</link></item></channel></rss>