Reputation: 11
Recently, I have built a connection with Twinfields API with a combination of VBA and Python. Twinfield is an accounting program, and I want to extract some data from it and use it in Excel. What I have programmed and working so far is the following: Logging in with my Twinfield credentials and getting a SessionID and the clusterURL; Getting all the administrations my login has access to; All transactions; and some more stuff. These all worked, so the problem is not my SessionID or URL or something.
Now I want to extract all known years and periods from Twinfield.
The problem I encounter is that i get error 500 back with the following text: The server was unable to process the request due to an internal error. For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the <serviceDebug> configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework SDK documentation and inspect the server trace logs.
My VBA-code is the following:
result = GetTwinfieldSession()
sessionID = result.sessionID
clusterURL = result.clusterURL & "/webservices/PeriodService.svc"
soapEnvelope = "<soap:Envelope xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:twin=""http://www.twinfield.com/"" xmlns:twin1=""http://schemas.datacontract.org/2004/07/Twinfield.WebServices.Shared"">" & _
" <soap:Header>" & _
" <twin:Header>" & _
" <twin1:SessionID>" & sessionID & "</twin1:SessionID>" & _
" <twin1:CompanyCode>" & TwinfieldAdminCode & "</twin1:CompanyCode>" & _
" </twin:Header>" & _
" </soap:Header>" & _
" <soap:Body>" & _
" <twin:Query i:type=""a:GetYears"" xmlns=""http://www.twinfield.com/"" xmlns:i=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:a=""http://schemas.datacontract.org/2004/07/Twinfield.Webservices.PeriodService""/>" & _
" </soap:Body>" & _
"</soap:Envelope>"
Set XMLHttp = CreateObject("MSXML2.XMLHTTP")
XMLHttp.Open "POST", clusterURL, False
XMLHttp.setRequestHeader "Content-Type", "text/xml"
XMLHttp.setRequestHeader "SOAPAction", "http://www.twinfield.com/PeriodService/Query"
XMLHttp.send soapEnvelope
As far as I can see this soapEnvelope is exactly the same as on the site: https://accounting.twinfield.com/webservices/documentation/#/ApiReference/Miscellaneous/Period, except that I use a SessionID and Twinfield uses a AccessToken in it's example
But sadly nothing I changed to my request worked. I tried using twin:Authentication, tried changing the companyCode to be in the body,
Does anyone know what is wrong with my code? Or do I need an AccessToken specifically for this request?
Thanks in advance!
Stefan Kraamer
Upvotes: 1
Views: 61