PDA

View Full Version : API call, send XML



Arany5
03-03-2023, 06:50 AM
Hello All,

I am trying to do an HTML post request, sending an XML file.
Here is the html version of what I need to achieve in VBA.
<html>
<head><meta content="text/html; CHARSET=UTF-8"></head>
<body>
<form action="https://www.szamlazz.hu/szamla/" method="post" enctype="multipart/form-data">
XML file: <input type="file" name="action-xmlagentxmlfile"><br><br>
E-mail attachments if applies:<br>
attached file 1. <input type="file" name="attachfile1"><br>
attached file 2. <input type="file" name="attachfile2"><br>
attached file 3. <input type="file" name="attachfile3"><br>
attached file 4. <input type="file" name="attachfile4"><br>
attached file 5. <input type="file" name="attachfile5"><br><br>
<input type="submit" name="generate" value="Issue invoice">
</form>
</body>
</html>



Here is my code so far:


Dim xmlhttp As Object
Dim env As String
Dim reqUrl As String
Dim allbody As String
Dim newbody As String
Dim response As String
Dim i, j As Integer
'Clear response fields - to do later
With Sheets("XML")
allbody = ""
For i = 1 To 70
For j = 1 To 3
allbody = allbody + CStr(.Cells(i, j).Value)
Next j
Next i
End With
Set xmlhttp = CreateObject("MSXML2.serverXMLHTTP")
reqUrl = "https://www.szamlazz.hu/szamla/"
xmlhttp.Open "POST", reqUrl, False
xmlhttp.setRequestHeader "name", "action-xmlagentxmlfile"
xmlhttp.send allbody
response = xmlhttp.responseText



This code at least sends out to the correct location and there is a response, but the response is not good, basically it is an html without content.
How do I send the XML as an attachment to the html? Should I send the above html with the xmlhttp.send? But in that case how do I add the attachment with the correct filename? How do I add multiple attachments?

Full documentation for the API is available here:
https://docs.szamlazz.hu/#post-request

I was trying to find a good example by searching, but could not find anything better. This is my first attempt at any API programming, so please beginner friendly answer.

Thanks!

Jan Karel Pieterse
03-03-2023, 12:45 PM
does it help to change to:

Set xmlhttp = CreateObject("MSXML2.XMLHTTP")

Arany5
03-08-2023, 05:16 AM
Thanks for your response, unfortunately I get the exact same response, that does not contain any useful data, just a generic html.