troubleshooting Question

MS Access VBA How To Properly Set Up A multipart/related HTTP Request

Avatar of Dustin Stanley
Dustin Stanley asked on
Microsoft AccessXMLVBAMicrosoft OfficeWeb Development
12 Comments2 Solutions674 ViewsLast Modified:
I need help in setting up a proper multipart/related HTTP request in VBA. If you can PLEASE show me samples in VBA of one.  A picture (Or Code) is worth a thousand words.

Here is my code for sending XML over HTTP currently:

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

Open in new window

This next code is in PHP (I think but I'm not sure.) but I need my VBA to be set up similiar:
 Accept-Encoding: gzip, deflate
 Accept: */*
 X-EBAY-SOA-SERVICE-NAME: FileTransferService
 Content-Length: 3936
 Connection: keep-alive
 Content-Type: multipart/related; boundary=MIME_boundary; type="application/xop+xml"; start="<0.urn:uuid:b2e95d5c-54ed-46ad-b479-fed744f2b8ca>"; start-info="text/xml"
 User-Agent: python-requests/2.5.1 CPython/3.3.4 Darwin/14.0.0
 Content-Type: application/xop+xml; charset=UTF-8; type="text/xml; charset=UTF-8"
 Content-Transfer_Encoding: binary
 Content-ID: <0.urn:uuid:b2e95d5c-54ed-46ad-b479-fed744f2b8ca>
 <uploadFileRequest xmlns:sct="" xmlns="">
 <Data><xop:Include xmlns:xop="" href="cid:urn:uuid:034d5afc-e1ac-4158-afab-8aae07e1423c"/></Data>
 Content-Type: application/octet-stream
 Content-Transfer-Encoding: base64
 Content-ID: <urn:uuid:034d5afc-e1ac-4158-afab-8aae07e1423c>
 H4sIALnxy1QC/60YaXPixvL7/go9f8l7S9biFmxpVU9c5gZzm1QqNWgGaUAH1owA+denR+IQttkkVdkqLzN9X9  **... MORE ENCODED DATA ....** PZ/vc0wdv/LK3Rj3bRphsdvlxJT+c58l0olS58V7G1JiQXaioJin7Iu/frHXwTk+//fvgnOnxkwFsUAAA=

Open in new window

Thank you for the help!
crystal (strive4peace) - Microsoft MVP, AccessRemote Training and Programming

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

Top Expert 2015

The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.

Log in to continue reading
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform for $9.99/mo
View membership options
Unlock 2 Answers and 12 Comments.
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
The Value of Experts Exchange in My Daily IT Life

Experts Exchange (EE) has become my company's go-to resource to get answers. I've used EE to make decisions, solve problems and even save customers. OutagesIO has been a challenging project and... Keep reading >>


Owner of Outages.IO
Phoenix, Arizona, United States
Member Since 2016
Join a full scale community that combines the best parts of other tools into one platform.
Unlock 2 Answers and 12 Comments.
View membership options
“All of life is about relationships, and EE has made a virtual community a real community. It lifts everyone's boat.”
William Peck

Member since 2004