?
Solved

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

Posted on 2017-04-06
13
Medium Priority
?
217 Views
Last Modified: 2017-04-20
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", "https://storage.sandbox.ebay.com/FileTransferService", 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="http://www.ebay.com/marketplace/services">
  '<!-- Call-specific Input Fields -->
  '<fileAttachment> FileAttachment
    '<Data><xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:urn:uuid:FileAttachment UUID Here"/></Data>
    '<Size>15</Size>
  '</fileAttachment>
  '<fileFormat>gzip</fileFormat>
  '<fileReferenceId>FILE REFRENCE ID HERE</fileReferenceId>
  '<taskReferenceId>JOB ID HERE</taskReferenceId>
'</uploadFileRequest>
'*************************************************************************************************************
    '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=""http://www.w3.org/2004/08/xop/include"" 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
        DoEvents
    Loop
    
    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
        
    Else
        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:
-----------START-----------
 POST https://storage.sandbox.ebay.com/FileTransferService
 Accept-Encoding: gzip, deflate
 X-EBAY-SOA-OPERATION-NAME: uploadFile
 Accept: */*
 X-EBAY-SOA-SERVICE-VERSION: 1.1.0
 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
 X-EBAY-SOA-SECURITY-TOKEN: **MYSANDBOXTOKEN**
 
 
 --MIME_boundary
 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="http://www.ebay.com/soaframework/common/types" xmlns="http://www.ebay.com/marketplace/services">
 <taskReferenceId>50008909051</taskReferenceId>
 <fileReferenceId>50009059491</fileReferenceId>
 <fileFormat>gzip</fileFormat>
 <fileAttachment>
 <Size>3121</Size>
 <Data><xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:urn:uuid:034d5afc-e1ac-4158-afab-8aae07e1423c"/></Data>
 </fileAttachment>
 </uploadFileRequest>
 
 
 --MIME_boundary
 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=
 --MIME_boundary--
 

Open in new window


Thank you for the help!
0
Comment
Question by:Dustin Stanley
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 2
  • 2
  • +1
13 Comments
 
LVL 35

Expert Comment

by:ste5an
ID: 42083474
What API call? Any reference link?
0
 

Author Comment

by:Dustin Stanley
ID: 42083513
Thank you. I am out of my office right now. I can get more information later today.

uploadFile https://developer.ebay.com/DevZone/file-transfer/CallRef/uploadFile.html

this is used through eBay Large Merchant Services

http://developer.ebay.com/DevZone/large-merchant-services/Concepts/LMS_APIGuide.html
0
 

Author Comment

by:Dustin Stanley
ID: 42084050
Here is the main API focuses of mine right now.

I am needing to make a call named AddFixedPriceItem.

This is going to be a multiple call combined into one. A repetitive AddFixedPriceItem call.

To combine several calls into one you have to use eBay "BulkDataExchangeRequest".

The only thing this means is that in the XML file I will have a call for AddFixedPriceItem that looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<BulkDataExchangeRequests xmlns="urn:ebay:apis:eBLBaseComponents">
  <Header>
    <Version>967</Version>
    <SiteID>0</SiteID>
  </Header>
<AddFixedPriceItemRequest xmlns="urn:ebay:apis:eBLBaseComponents">
  <ErrorLanguage>en_US</ErrorLanguage>
  <WarningLevel>High</WarningLevel>
  <Version>967</Version>
  <Item>
    <CategoryMappingAllowed>true</CategoryMappingAllowed>
    <Country>US</Country>
    <Currency>USD</Currency>
    <Description>Minimal fixed-price shoe listing with SKU, free shipping, 3-day dispatch time, return policy, and no Item Specifics. New Nike Shox Elite TB White/White-Black-Chrome. Size: Mens US 12, UK 11, Europe 46 (Medium, D, M). Condition: New in box.</Description>
    <DispatchTimeMax>3</DispatchTimeMax>
    <InventoryTrackingMethod>SKU</InventoryTrackingMethod>
    <ListingDuration>Days_30</ListingDuration>
    <ListingType>FixedPriceItem</ListingType>
    <Location>San Jose, CA</Location>
    <PaymentMethods>PayPal</PaymentMethods>
    <PayPalEmailAddress>MegaOnlineMerchant@gmail.com</PayPalEmailAddress>
    <PrimaryCategory>
      <CategoryID>63850</CategoryID>
    </PrimaryCategory>
    <Quantity>6</Quantity>
    <ReturnPolicy>
      <ReturnsAcceptedOption>ReturnsAccepted</ReturnsAcceptedOption>
      <RefundOption>MoneyBack</RefundOption>
      <ReturnsWithinOption>Days_30</ReturnsWithinOption>
      <Description>Text description of return policy details here.</Description>
      <ShippingCostPaidByOption>Buyer</ShippingCostPaidByOption>
    </ReturnPolicy>
    <ShippingDetails>
      <ShippingType>Flat</ShippingType>
      <ShippingServiceOptions>
        <ShippingServicePriority>1</ShippingServicePriority>
        <ShippingService>USPSPriority</ShippingService>
        <ShippingServiceCost currencyID="USD">0.0</ShippingServiceCost>
        <ShippingServiceAdditionalCost>0.00</ShippingServiceAdditionalCost>
        <FreeShipping>true</FreeShipping>
      </ShippingServiceOptions>
    </ShippingDetails>
    <Site>US</Site>
    <SKU>1122334455-14</SKU>
    <StartPrice>50.00</StartPrice>
    <Title>New Nike Shox Elite TB White Mens Basketball Shoes S 12</Title>
    <UUID>7d004a30b0f511ddad8b0807654c9a56</UUID>
  </Item>
</AddFixedPriceItemRequest>
<AddFixedPriceItemRequest xmlns="urn:ebay:apis:eBLBaseComponents">
  <ErrorLanguage>en_US</ErrorLanguage>
  <WarningLevel>High</WarningLevel>
  <Version>967</Version>
  <Item>
    <CategoryMappingAllowed>true</CategoryMappingAllowed>
    <Country>US</Country>
    <Currency>USD</Currency>
    <Description>Minimal fixed-price shoe listing with SKU, free shipping, 3-day dispatch time, return policy, and no Item Specifics. New Nike Shox Elite TB BLACK / WHITE-VARSITY RED. Size: Mens US 12, UK 11, Europe 46 (Medium, D, M). Condition: New in box.</Description>
    <DispatchTimeMax>3</DispatchTimeMax>
    <InventoryTrackingMethod>SKU</InventoryTrackingMethod>
    <ListingDuration>Days_30</ListingDuration>
    <ListingType>FixedPriceItem</ListingType>
    <Location>San Jose, CA</Location>
    <PaymentMethods>PayPal</PaymentMethods>
    <PayPalEmailAddress>MegaOnlineMerchant@gmail.com</PayPalEmailAddress>
    <PrimaryCategory>
      <CategoryID>63850</CategoryID>
    </PrimaryCategory>
    <Quantity>6</Quantity>
    <ReturnPolicy>
      <ReturnsAcceptedOption>ReturnsAccepted</ReturnsAcceptedOption>
      <RefundOption>MoneyBack</RefundOption>
      <ReturnsWithinOption>Days_30</ReturnsWithinOption>
      <Description>Text description of return policy details here.</Description>
      <ShippingCostPaidByOption>Buyer</ShippingCostPaidByOption>
    </ReturnPolicy>
    <ShippingDetails>
      <ShippingType>Flat</ShippingType>
      <ShippingServiceOptions>
        <ShippingServicePriority>1</ShippingServicePriority>
        <ShippingService>USPSPriority</ShippingService>
        <ShippingServiceCost currencyID="USD">0.0</ShippingServiceCost>
        <ShippingServiceAdditionalCost>0.00</ShippingServiceAdditionalCost>
        <FreeShipping>true</FreeShipping>
      </ShippingServiceOptions>
    </ShippingDetails>
    <Site>US</Site>
    <SKU>1122334455-15</SKU>
    <StartPrice>55.00</StartPrice>
    <Title>New Nike Shox Elite TB Black Mens Basketball Shoes S 12</Title>
    <UUID>7d005a30b0f511ddad8b0876540c9a57</UUID>
  </Item>
</AddFixedPriceItemRequest>
</BulkDataExchangeRequests>

Open in new window


You can see in the example above there are 2 AddFixedPriceItem Calls.  To send them together you have to Wrap them in the Main Root "BulkDataExchangeRequests".

Then AddFixedPriceItem XML file has to be encoded in Base64 Binary format and included in the request according to the SOAP MTOM standard.

That's it for the AddFixedPriceItem XML file.
Specs (For the Bulk Call it is towards the end of this page at this link below: http://developer.ebay.com/devzone/xml/docs/reference/ebay/AddFixedPriceItem.html
****************************************************************************************************
In order to send that "AddFixedPriceItem XML File" I have to make the main call named "uploadFile" with AddFixedPriceItem as an attachment.

Specs: https://developer.ebay.com/DevZone/file-transfer/CallRef/uploadFile.html

The uploadFile XML file looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<uploadFileRequest xmlns="http://www.ebay.com/marketplace/services">
  <!-- Call-specific Input Fields -->
  <fileAttachment>
    <Data><xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:urn:uuid:7d005a30b0f511ddad8b0876540c9a55"/></Data>
    <Size>15</Size>
  </fileAttachment>
  <fileFormat>gzip</fileFormat>
  <fileReferenceId>50047856</fileReferenceId>
  <taskReferenceId>50012766</taskReferenceId>
</uploadFileRequest>

Open in new window


If you look at Line 5 <Data> there is a special UUID that I generated. This UUID (Line 5) is there and mandatory so you do not accidentally upload the same thing multiple times. Each upload has to have a new UUID.

I have to send both of these files together for this call (uploadFile as the main call) & (AddFixedPriceItem as the fileAttachment)

*****************************************************************************************************

So this is where I am struggling I have to Set Up A multipart/related HTTP Request and I do not know exactly how.

I hope this helps. I thank you very much for the help.
0
Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

 

Author Comment

by:Dustin Stanley
ID: 42099839
This seems like a rare thing here on Experts-Exchange or anywhere online. It would be nice for a good tutorial for future visitors.

So far I have not had any luck except with using ChillKat Software. But as far as for VBA nothing.
0
 
LVL 22

Accepted Solution

by:
crystal (strive4peace) - Microsoft MVP, Access earned 2000 total points
ID: 42099934
Hi Dustin,

here is an EE thread that may help:

How do I detach/Save/Open a ZIP file that has been embedded in an XML output file?
https://www.experts-exchange.com/questions/26819850/How-do-I-detach-Save-Open-a-ZIP-file-that-has-been-embedded-in-an-XML-output-file.html
0
 

Author Comment

by:Dustin Stanley
ID: 42099968
Thank you crystal I read that post so many times. They never really finished it so....... Another lead but it helped.
1
 
LVL 58
ID: 42100384
This expert suggested creating a Gigs project.
Dustin,

 I'm not sure what your question is here,   Other than the fact that you seem to be saying   " please do this for me ".

   I do know you have tried on this, but I wanted to say that this is where many of us on EE would draw the line and that is actually doing the work. It's one thing to help you out with a problem or two but it's another to sit down and actually write the thing,  which is what many of us do professionally for a living  and charge clients for.

  I did see the gigs you posted, but respectfully the price was way too low. This is where many people that don't develop fail to understand the time  and effort  it takes to develop a good piece of code  or application

  You do have all the pieces to this.  the problem is nothing more than working with the pieces you've already asked questions on.  

 I would suggest the gigs approach again, but offer more what the job is worth. This is probably in the range of 12 to 16 hours worth of work by the time someone understands what needs to be done, actually codes it, tests it,  handles any issues that arise, and documents it all.

 Food for thought,

Jim
0
 

Author Comment

by:Dustin Stanley
ID: 42100488
I thank you Jim and please don't take this question in that way. I am not an expert and I do not want anyone to do this for me.

I have collected a ton of information and I would like to even make the post of the proper tutorial myself but I do not want to mis inform anyone.

There is procedures you have to do and you have to have exact spacing for the server to understand the MIME Also some other details that has to be exactly correct or the MIME fails.

Also the "Gig" I posted before was seriously more of a help me through this so I can learn. Just as always I want to learn this. Not for you to do it for me.

The main request here is just to show the proper way to set up a multi part / related MIME.......

Which I have found out there is not very much info online about how to do this in VBA.

I have already succeeded in my exact procedure but there are a few things I am still unsure of. I thought "Hey I could delete this question but hopefully some experts would chime in and show some good solid answers for future visitors" ......but then I thought "I can write a tutorial but I am not 100% sure more like 60%".

Anyway I thank you for help you have always given me and I do not want to come off as a (what I would call a BUM) or a butt.

But (no pun intended :)) this would be a HUGE chance for future visitors if this question thoroughly got answered correctly.

Thanks Jim
0
 
LVL 58
ID: 42100589
I thank you Jim and please don't take this question in that way.

 And I hope you didn't take my comment the wrong way either.  I was simply trying to point out why you were not getting responses.   This has reached the point where someone needs simply "do it" one way or another.

 Unless you keep the questions small and focused on one paticular aspect, no one will grab onto this.   It's too much of a project as a whole.   Also read on.

The main request here is just to show the proper way to set up a multi part / related MIME.......
Which I have found out there is not very much info online about how to do this in VBA.

Maybe that's part of the disconnect here; understand that when you reach a certain point, there is no "right way" to do something and two people may develop the same solution in entirely different ways.   One may be better than the other when it comes to maintaining it in the future or doing it with less code, or being more efficient, but you can't stand back and say necessarily one is right or wrong if both produce the same result.

 What Classes, Procedures, code, etc someone comes up with is in most aspects unique.  So again, until someone would sit down and actually do this, your probably not going to get an answer.

 If you want to continue doing this on your own, my suggestion would be to start at the beginning, build it up bit by bit, and ask a series of focused questions (something that can be understood and answered within minutes) on a very specific part that your trying to do.

  In asking a generalized question like this about the whole task, your not going to get any takers.

Jim.
0
 

Assisted Solution

by:Dustin Stanley
Dustin Stanley earned 0 total points
ID: 42100831
This code below is not a 100% perfect code. But I hope this helps someone out there:
Option Compare Database
Option Explicit

Public Function uploadFileTest()
    Dim Http As New MSXML2.XMLHTTP40
    Dim Doc As New MSXML2.DOMDocument
    Dim lngLength As Long
    Dim TokenValue As String
    Dim APICALL As String
    Dim DevName As String
    Dim AppName As String
    Dim CertName As String
    Dim FP1 As String
    Dim Service As String
    Dim xmlFile As String
    Dim XMLUUID As String
    Dim RequestUUID As String
    Dim FileAttachmentUUID As String
    Dim ContentType As String
    Dim strBody As String
    Dim TaskRefId As String
    Dim FileRefId As String
    Dim strFileName As String
    Dim strFile As String
    Dim Filename As String
    
     ' On Error GoTo Proc_Err
'***********************************************************************************************************
'Things you need to add your own values too
'***********************************************************************************************************

    TokenValue = "TOKEN CODE HERE" ' This is used for the Token Code insert manually on the Form Ebay Add Fixed Price Item.
    DevName = "DEV NAME HERE" 'Supplied by ebay.
    AppName = "APP NAME HERE" 'Supplied by ebay.
    CertName = "CERT NAME HERE" 'Supplied by ebay.
    FP1 = "FILE PATH HERE" & "\" ' Path to your files"
    Filename = "FILE NAME HERE" & ".gz" ' Name of File to be uploaded (gzip File)
    
'***********************************************************************************************************
'For this call you need 3 UUIDs You will have to change these values for every call
'***********************************************************************************************************
    RequestUUID = "REQUEST UUID HERE" 'This is the MIME Boundary
    XMLUUID = "XML UUID HERE" 'XML UUID This is to show which file you are refering to in the http header "Start="
    FileAttachmentUUID = "FILE ATTACHMENT UUID HERE" ' This is the File Attachment UUID to show what Gzip file you are uploading.
     
'***********************************************************************************************************
    
    strFileName = FP1 & Filename
    lngLength = Len(strBody) ' the length of the HTTP request
    Service = "FileTransferService"
    ContentType = "multipart/related; boundary=MIMEBoundaryurn_uuid_" & RequestUUID & ";type=""application/xop+xml"";start=" & """" & "<0.urn:uuid:" & XMLUUID & ">"";start-info=""text/xml"""
    TaskRefId = "JobID AKA Task Ref ID HERE" 'DLookup("jobId", "createUploadJobResponse") 'NOT THE BEST SOLUTION BUT WORKS
    FileRefId = "FilereferenceID HERE" 'DLookup("fileReferenceId", "createUploadJobResponse") 'NOT THE BEST SOLUTION BUT WORKS
    APICALL = "uploadFile" ' MORE INFO HERE: https://developer.ebay.com/DevZone/file-transfer/CallRef/uploadFile.html
    
    
    'uploadFile XML File
    xmlFile = "<?xml version=""1.0"" encoding=""UTF-8""?><uploadFileRequest xmlns=""http://www.ebay.com/marketplace/services""><taskReferenceId>" & TaskRefId & "</taskReferenceId><fileReferenceId>" & FileRefId & "</fileReferenceId><fileFormat>gzip</fileFormat><fileAttachment><Data><xop:Include href=""cid:urn:uuid:" & FileAttachmentUUID & """  xmlns:xop=""http://www.w3.org/2004/08/xop/include""/></Data><Size>15</Size></fileAttachment></uploadFileRequest>"
    strFile = GetFile(strFileName) 'Calls GetFile and loads the (Gzip Format) File as a binary attachment.


'***********************************************************************************************************
'Build The body
'***********************************************************************************************************
strBody = vbNewLine & vbNewLine & "--MIMEBoundaryurn_uuid_" & RequestUUID & vbNewLine 'Unsure of line spacing between header and Body 1,2,or 3?????
'strBody = strBody & "Content-Disposition: form-data; name="fieldNameHere"; filename="uploadFileNEWGOOD.xml" & vbNewLine
strBody = strBody & "Content-Type: text/xml" & vbNewLine
strBody = strBody & "Content-Transfer-Encoding: binary" & vbNewLine
strBody = strBody & "Content-ID: <0.urn:uuid:" & XMLUUID & ">" & vbNewLine
strBody = strBody & vbNewLine  'Space between XML File Header and XML File Body!

strBody = strBody & xmlFile & vbNewLine 'XML uploadFile File Body!
strBody = strBody & "--MIMEBoundaryurn_uuid_" & RequestUUID & vbNewLine
'strBody = strBody & "Content-Disposition: form-data; name="fieldNameHere"; filename="AFPIBulkTest1.gz" & vbNewLine
strBody = strBody & "Content-Type: application/x-gzip" & vbNewLine
strBody = strBody & "Content-Transfer-Encoding: binary" & vbNewLine
strBody = strBody & "Content-ID: <0.urn:uuid:" & FileAttachmentUUID & ">" & vbNewLine
strBody = strBody & vbNewLine  'Space between File Attachment Header and File Attachment Body!

        

strBody = strBody & Split(strFile, Chr(0))(0)
    strBody = strBody & vbNewLine & "--MIMEBoundaryurn_uuid_" & RequestUUID & "--"

Debug.Print Asc(Right(strFile, 1))
    Debug.Print Asc(Right(strFile, 2))

'***********************************************************************************************************
'Load the XML file uploadFile and Set your headers.
'***********************************************************************************************************
    
    
    Doc.Load FP1 & APICALL & ".xml" 'Document Location of the XML File With Items Being Added

    
    Http.Open "POST", "https://storage.sandbox.ebay.com/FileTransferService", False 'CHANGE FOR PRODUCTION!
    Http.setRequestHeader "Content-type", ContentType
    Http.setRequestHeader "X-EBAY-SOA-SERVICE-NAME", Service
    Http.setRequestHeader "X-EBAY-SOA-OPERATION-NAME", APICALL
    Http.setRequestHeader "X-EBAY-SOA-SECURITY-TOKEN", TokenValue
    Http.setRequestHeader "X-EBAY-SOA-REQUEST-DATA-FORMAT", "XML"
    Http.setRequestHeader "X-EBAY-SOA-RESPONSE-DATA-FORMAT", "XML"
    Http.setRequestHeader "Content-Length", lngLength ' the length of the HTTP request
    
   
    MsgBox xmlFile, , "uploadFile XML" ' Message box to show you what the uploadFile XML file looks like you are sending.
    MsgBox strBody, , "String Body" ' Message box to show you MOST of the MIME body you are sending. Take note the Message box cuts alot of it off. No concern.
    
    
    Call SaveStringAsTextFile(FP1 & "strBody.txt", strBody) 'Save strBody to file to examine.
'***********************************************************************************************************
'The Call is being made next.
'***********************************************************************************************************
    Http.send strBody 'This sends the XML document from above.

Do Until Http.ReadyState = 4
        DoEvents
    Loop

    MsgBox (Http.responseText), , "Response" 'Success or Failure

    If Http.Status = 200 Then
        Set Doc = Http.responseXML
        Doc.Save FP1 & APICALL & "_ReturnFile.xml" 'This is the return response from ebay after the document is sent and they process it.

        Application.ImportXML FP1 & APICALL & "_ReturnFile.xml", acAppendData

    Else
        MsgBox "Error " & Err.Number & ": " & Err.Description & " in " & _
   VBE.ActiveCodePane.CodeModule, vbOKOnly, "Error"
    End If
    Set Http = Nothing

  

Exit Function ' sub
  
Proc_Err:
   MsgBox Err.Description, , _
        "ERROR " & Err.Number _
        & "   UploadFileRequest"
End Function

'*********************************************
'Returns file contents As a binary data
'*********************************************
Function GetFile(Filename)
  Dim Stream: Set Stream = CreateObject("ADODB.Stream")
  Stream.Type = 1 'Binary is value 1.
  Stream.Open
  Stream.LoadFromFile Filename
  GetFile = Stream.Read
  Stream.Close
End Function

Public Sub SaveStringAsTextFile(psPathFile As String, psFileContents)
'160730 strive4peace
   Dim iFile As Integer
   
   iFile = FreeFile
   Open psPathFile For Output As iFile
   Print #iFile, psFileContents
   Close iFile

End Sub

Open in new window

0
 

Author Closing Comment

by:Dustin Stanley
ID: 42100833
Thank you.
0
 
LVL 22
ID: 42100866
you're welcome, and thanks for sharing, Dustin ~
0

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
Ever wonder what it's like to get hit by ransomware? "Tom" gives you all the dirty details first-hand – and conveys the hard lessons his company learned in the aftermath.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question