troubleshooting Question

HELP! MS Access VBA How Do you Add Attachments To XML Files Before Sending Over HTTP As API Call

Avatar of Dustin Stanley
Dustin Stanley asked on
Microsoft AccessXMLVBA
36 Comments1 Solution675 ViewsLast Modified:
This part is like banging your head against the wall!!!

It just don't make sense!

I have an XML file called uploadFile:

<?xml version="1.0" encoding="utf-8"?>
<uploadFileRequest xmlns="">
  <!-- Call-specific Input Fields -->
  <fileAttachment> FileAttachment
    <Data> base64Binary </Data>
    <Size> long </Size>
  <fileFormat> token </fileFormat>
  <fileReferenceId> string </fileReferenceId>
  <taskReferenceId> string </taskReferenceId>

I also have another XML file called Test14 that I gZipped up.  As I understand it  I have to attach Test14 within uploadFile where it says FileAttachment <Data> with a Cid UUID (I may be completely wrong. This may not be how VBA works) but that is what I understand.

API Call uploadFile Specs:

I am able to send the call with just uploadFile XML file but the attachment isn't there so it keeps returning an error of invalid Attachment.

Here is my HTTP Code:
Option Compare Database
Option Explicit

Public Function EbaySenderXmlAddFixedPriceItems()
Dim reader As New MSXML2.XMLHTTP40
    Dim doc As New MSXML2.DOMDocument 'If you want to load the XML Document instead of creating it.
    Dim TokenValue As String
    Dim APICALL As String
    'API Call Name!
      APICALL = "uploadFile" 'Place the API Call Name here within the parenthesis.
    'Place Token Value Here Below!
    TokenValue = "TOKEN GOES HERE Like ujhuhuaeuyaeyayuo8i"
    doc.Load "C:\Users\Station\Documents\Access XML Save Files\uploadFile.xml" 'Document Location of the XML File With Items Being Added
    'Set The Headers Up!
    reader.Open "POST", "", False
    reader.setRequestHeader "Content-ID", "<0.urn.uuid:FileAttachment UUID Here>" 'Must include FileAttachment UUID that matches the FileAttachment UUID!
    reader.setRequestHeader "X-EBAY-SOA-OPERATION-NAME", APICALL 'API Call Name
    reader.setRequestHeader "X-EBAY-SOA-SECURITY-TOKEN", TokenValue ' This is your Highly Secret Token. Place the Token above in the code where it says "Place Token Value Here!".
    reader.setRequestHeader "X-EBAY-SOA-SERVICE-VERSION", "1.5.0" 'Usually never have to change this unless if there is an update.
    reader.setRequestHeader "X-EBAY-API-SITEID", "0" ' 0 is for the USA Site!
    reader.setRequestHeader "X-EBAY-API-DEV-NAME", "Dev Name Here" 'Developers Name Code.
    reader.setRequestHeader "X-EBAY-API-APP-NAME", "App Name Here" 'Applications Name Code.
    reader.setRequestHeader "X-EBAY-API-CERT-NAME", "Certificate Name Here" 'Certificate Name Code.
    'Use The Code After The Example Below To Build The XML File Instead Of Loading An Already Existing One!
    'Expected OutPut Example!
    '<?xml version="1.0" encoding="UTF-8"?>
'<uploadFileRequest xmlns="">
  '<!-- Call-specific Input Fields -->
  '<fileAttachment> FileAttachment
    '<Data><xop:Include xmlns:xop="" href="cid:urn:uuid:FileAttachment UUID Here"/></Data>
  '<fileReferenceId>FILE REFRENCE ID HERE</fileReferenceId>
  '<taskReferenceId>JOB ID HERE</taskReferenceId>
    'Dim uploadFile As String 'If you want to create the XML Document instead of loading it.
    'uploadFile = ""
    'uploadFile = uploadFile & "<?xml version=""1.0"" encoding=""UTF-8""?>" & vbNewLine
    'uploadFile = uploadFile & "<fileAttachment>" & vbNewLine
    'uploadFile = uploadFile & "<Data><xop:Include xmlns:xop="""" href=""cid:urn:uuid:9eda0520-1a27-11e7-93ae-92361f002671""/></Data>" & vbNewLine
    'uploadFile = uploadFile & "<Size>15</Size>"
    'uploadFile = uploadFile & "<fileFormat>gzip</fileFormat>" & vbNewLine
    'uploadFile = uploadFile & "<fileReferenceId>50015247856</fileReferenceId>" & vbNewLine
    'uploadFile = uploadFile & "<taskReferenceId>50012765386</taskReferenceId>" & vbNewLine
    'uploadFile = uploadFile & "</uploadFileRequest>"
       'MsgBox uploadFile 'Shows MessageBox of the created XML file above.
         'reader.send uploadFile 'This sends the XML document from above that was created.

    reader.send doc 'This sends the XML document from above that was loaded.
Do Until reader.ReadyState = 4
    MsgBox (reader.responseText) 'Shows MessageBox of the Servers Response. ie...Success or Error!
    If reader.Status = 200 Then
        Set doc = reader.responseXML
        doc.Save "C:\Users\Station\Documents\Access XML Save Files\New Testing\eBayReturnFile.xml" 'This is the return response from ebay after the document is sent and they process it.
         'MsgBox "PERFECT JUST LIKE YOU :)"
        Application.ImportXML "C:\Users\Station\Documents\Access XML Save Files\New Testing\eBayReturnFile.xml", acStructureAndData
        MsgBox "Error " & Err.Number & ": " & Err.Description & " in " & _
   VBE.ActiveCodePane.CodeModule, vbOKOnly, "Error"
    End If
    Set reader = Nothing
End Function

Also the gZip is in binary64 format if that helps with info.

Maybe they just both have to be sent together but either way I have no idea on how to accomplish this.

Please help and I thank you very much for any help I get!


Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 36 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 36 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros