Hi. I'm trying to figure out an XML error that has me stuck.
I am actually trying to retrieve order information from inside an Excel spreadsheet using VBA. I know, it isn't the greatest platform, but it's what I have to work with for this particular task. At any rate:
Below is the code I have. I have verified that it can send good XML by sending it to my own web page and verifying that the function sends and receives properly. When I try to get an Unsettled Transaction List from Authorize.NET, however, it fails with an E00003 Root Element Is Missing error. Here's my code:
Private Sub getUnsettledTransactions_Click() Worksheets("Sheet1").Range("B49") = "" 'Where I show the sent XML Worksheets("Sheet1").Range("B53") = "" 'Where I show what's received back 'HTTP variable Dim myHTTP As MSXML2.XMLHTTP 'HTTP object Set myHTTP = CreateObject("msxml2.xmlhttp") 'create dom document variable, stores the xml to send Dim myDom As MSXML2.DOMDocument 'Create the DomDocument Object Set myDom = CreateObject("MSXML2.DOMDocument") 'Load entire Document before moving on myDom.async = False 'xml string variable Dim myxml As String
myxml = "<?xml version=""1.0""?>" & _ "<getUnsettledTransactionListRequest xmlns=""AnetApi/xml/v1/schema/AnetApiSchema.xsd"">" & _ "<merchantAuthentication>" & _ "<name>12345</name>" & _ "<transactionKey>12345</transactionKey>" & _ "</merchantAuthentication>" & _ "</getUnsettledTransactionListRequest>" Worksheets("Sheet1").Range("B49") = myxml 'Write the XML to be sent 'open the connection myHTTP.Open "post", "https://apitest.authorize.net/xml/v1/request.api", False myHTTP.setRequestHeader "Content-Type", "text/xml" myHTTP.setRequestHeader "Content-Length", Len(myxml) 'send the XML myHTTP.Send (myDom.XML) 'Display the response Worksheets("Sheet1").Range("B53") = myHTTP.ResponseText 'XML we get back End Sub
And here's the XML error I get back:
<?xml version="1.0" encoding="utf-8"?>
<ErrorResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">
<messages>
<resultCode>Error</resultCode>
<message>
<code>E00003</code>
<text>Root element is missing.</text>
</message>
</messages>
</ErrorResponse>
OK, so just to do a sanity check, I try doing the same thing in Python. That checks to make sure I have that functionality turned on in my Authorize.net test account. The code below works well (in Python), and I successfully get an XML list of unsettled transactions.
import sys, httplib def do_requests(request): webservice = httplib.HTTPS(HOST) webservice.putrequest("POST", API_URL) webservice.putheader("Host", HOST) webservice.putheader("Content-type", "text/xml; charset=\"UTF-8\"") webservice.putheader("Content-length", "%d" % len(request)) webservice.endheaders() webservice.send(request) statuscode, statusmessage, header = webservice.getreply() result = webservice.getfile().read() print "------------------------------------------" print statuscode, statusmessage, header print "------------------------------------------" print result print "------------------------------------------" print "Send a getUnsettledTransactionListRequest to Authorize.net:" HOST = "apitest.authorize.net" API_URL = '/xml/v1/request.api' myxml = '<?xml version="1.0"?><getUnsettledTransactionListRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"><merchantAuthentication><name>1234</name><transactionKey>1234</transactionKey></merchantAuthentication></getUnsettledTransactionListRequest>' do_requests(myxml)
Other than a few bad characters at the front of the output (probably a Python 2.7 ascii vs. unicode problem), I get the XML output just fine.
Any suggestions or advice would be appreciated. Why does it work in the Python example, but not in my Excel/VBA example? Is there another header I need? What does that "Root Element Is Missing" actually mean?
The VBA script seems to send the complete XML text well to my test page.
Solved! Go to Solution.
11-16-2012 01:40 PM
Thanks for the quick answer. I'm rookie enough with doing this that the answer could be that simple. Unfortunately, that didn't fix it. I inserted the myDom.Load (myxml) before the myHTTP.Send (myDom.XML) as you suggested, and it didn't make a difference. I still get the E00003 Root Element Is Missing error.
Your reply prompted me to take a fresh, thorough look for any differences between my (even simpler) working example and this particular non-working code. Sure enough, I had commented out the line:
myDom.loadXML (myxml)
I put that in and it works like a charm. Thanks for getting me back on track!
11-19-2012 12:18 PM
I think you forgot the
myDom.Load (myxml)
before the
myHTTP.Send (myDom.XML)
11-16-2012 02:12 PM
Thanks for the quick answer. I'm rookie enough with doing this that the answer could be that simple. Unfortunately, that didn't fix it. I inserted the myDom.Load (myxml) before the myHTTP.Send (myDom.XML) as you suggested, and it didn't make a difference. I still get the E00003 Root Element Is Missing error.
Your reply prompted me to take a fresh, thorough look for any differences between my (even simpler) working example and this particular non-working code. Sure enough, I had commented out the line:
myDom.loadXML (myxml)
I put that in and it works like a charm. Thanks for getting me back on track!
11-19-2012 12:18 PM
Hello, I am also getting a XML error when hitting the URL: https://apitest.authorize.net/soap/v1/Service.asmx?wsdl. As the other user is also seeing, it looks like an issue with the sandbox. The type of error that I am seeing is usually associated with an invalid SSL certificate.
Mind you, as of last week, this code was working.....this error has only occurred within the past few days. I am consuming this WSDL location directly using PHP.
Can someone on the Authorize.NET side check the server logs and check the security layer for issues or any of the problems that may be occurring server-side?
11-28-2012 05:46 AM