I have developed a VBA application in order to upload xml invoice files to a specific REST API endpoint. Last year the application worked perfect. Now, when the xml invoice has more than 50 lines (I suppose this is related to file dimension actually), I'm getting a wrong response from the server. The context difference is made by the fact that now there are a lot more companies that are uploading a big number of invoices.
According to the documentation, if the response status is 200, then the response should be an xml file like this:
Instead, even if the response status is 200, the response is an html file that includes the text message "System Maintenance". The invoice no of lines and the xml file dimension do fit into the limits specified by the documentation provided. In addition, the xml invoice file in correct, as it can be uploaded manually into the web interface provided for manual upload.
Please let me know what I'm doing wrong or what should I do in order to get rid off that html file and get the right response. Thanks a lot for your help.
Here is the part of the code I'm using for the API POST request:
'Certificate details
Dim tk As String
tk = "12345"
Dim user As String
user = "CURRENT_USER\MY\USER"
'API endpoint
URL = "https://webservices/rest/upload.."
Set http = CreateObject("MSXML2.ServerXMLHTTP.6.0")
'Open URL As POST request
http.Open "POST", URL, False
http.SetRequestHeader "Authorization", "Bearer " & tk
http.setOption 3, user
http.SetRequestHeader "Accept", "application/xml"
http.SetRequestHeader "Content-Type", "application/xml"
http.Send invoicexml
if http.status = 200 Then
MsgBox "Response: " & http.ResponseText
Else
MsgBox "Error: " & http.status & " - " & http.StatusText
End If
After getting the wrong response I have tried an asynchronous request as well, but I've got the same html file as response:
http.Open "POST", URL, True
http.SetRequestHeader "Authorization", "Bearer " & tk
http.setOption 3, user
http.SetRequestHeader "Accept", "application/xml"
http.SetRequestHeader "Content-Type", "application/xml"
http.Send invoicexml
Do While http.readyState <> 4
DoEvents
Loop
' Check the status code and process the response
If http.status = 200 Then
MsgBox "Response: " & http.ResponseText
Else
MsgBox "Error: " & http.status & " - " & http.StatusText
End If