Can I use MS Access to send an HTTP Post and Get

Posted on 2014-08-08
Last Modified: 2014-09-15
Hello Experts,

I am trying to use the programmatic upload feature of eBay's File Exchange system to send a CSV file to eBay's file exchange server.

I am hoping for VBA code that I can put into a command button's OnClick event.

Ebay has provided the following instructions:

1.  To upload your file programmatically, send an HTTP Post request to the File Exchange
server to accept.

2. Initiate an HTTPS connection then post your data file with your token to the File Exchange URL:

See Sample HTTP Post Request:

POST /path/to/upload/script HTTP/1.0
Connection: Keep-Alive
User-Agent: My Client App v1.0
Content-type: multipart/form-data;
Content-Length: 256
Content-Disposition: form-data; name="token"
Content-Disposition: form-data; name="file";
Content-Type: text/csv
contents of listing.csv ...
Question by:pcalabria
    LVL 84

    Accepted Solution

    VBA can use the SOAP methods for this. Here's a good example:

    Basically, you create the "request" string in the format expected by the web service, and then you "Post" that string to the webservice.

    More specifically, the Expert provided a working example in this comment:

    Note the use of XML in that question. You don't need to worry with that part, since your webservice expects a "text/scv" file format.
    LVL 56

    Assisted Solution

    by:Jim Dettman (Microsoft MVP/ EE MVE)
    I don't understand all the various methods you can use to talk to a web site, but here's all that I did:

              ' Capture the CC

                ' Set the correct URL
                'strPostURL = ""
                strPostURL = ""
                'strPostURL = ""

                strPostSting = ""
                strPostSting = strPostSting & "x_login=" & URLEncode(strAPILogin) & "&"
                strPostSting = strPostSting & "x_tran_key=" & URLEncode(strTransactionKey) & "&"
                'For debugging.
                'strPostSting = strPostSting & "x_test_request=" & URLEncode("TRUE") & "&"
                strPostSting = strPostSting & "x_version=" & URLEncode("3.1") & "&"
                strPostSting = strPostSting & "x_delim_data=" & URLEncode("TRUE") & "&"
                strPostSting = strPostSting & "x_delim_char=" & URLEncode("|") & "&"
                strPostSting = strPostSting & "x_relay_response=" & URLEncode("FALSE") & "&"
                strPostSting = strPostSting & "x_email_customer=" & URLEncode("FALSE") & "&"

                strPostSting = strPostSting & "x_type=" & URLEncode("PRIOR_AUTH_CAPTURE") & "&"
                strPostSting = strPostSting & "x_trans_id=" & URLEncode(rs!CCTransactionID) & "&"

                ' Additional fields can be added here as outlined in the AIM integration
                ' guide at:
                strPostSting = left(strPostSting, Len(strPostSting) - 1)

                ' We use xmlHTTP to submit the input values and record the response
                Dim objRequest As New MSXML2.XMLHTTP
                objRequest.Open "POST", strPostURL, False
                objRequest.Send strPostSting
                strPostResponse = objRequest.responseText
                'Debug.Print strPostResponse
                Set objRequest = Nothing

                ' the response string is broken into an array using the specified delimiting character
                arrResponse = Split(strPostResponse, "|", -1)

                If arrResponse(0) = 1 Then

     this required a reference to the Microsoft XML 6.0 lib.


    Author Comment

    I guess I didn't understand how much I don't understand!  I have to use XML?
    I was thinking I would create an HTML document .. Save it to disk.. And then somehow submit!?

    I didn't understand either reply.
    LVL 56

    Expert Comment

    by:Jim Dettman (Microsoft MVP/ EE MVE)
    Well in the example I posted, there was no XML involved.   I was simply sending a string to a web site, and getting string in return.   I used the XML library because it had the methods to send/receive from a web site, but there was no XML involved.  In the SOAP examples that Scott posted, there was.

    Like anything, there are various ways to talk to a web site.   But basically, it's a stream of string data.  Of course what's in the string is where the difference come in.
    From what you posted, it looks to me like you just need the POST and GET methods of HTTP and I would try to use the example I gave and see if it works.  If you look closely, you'll see that all I did was send a string:

                objRequest.Open "POST", strPostURL, False
                objRequest.Send strPostSting

     after opening a connection to a URL, and got a string in response:

               strPostResponse = objRequest.responseText

    LVL 84
    From what I can see of your requirements, the code Jim posted should do what you need - providing, of course, that your  Text file is properly formed. If your sample text is what EBay expects to get, then you'd simply modify Jim's post to create that text string, and send it to the URL you included in your original post.

    FWIW - it's much, much easier to do this in .NET, since that can interact directly with the web service. If you're at all comfortable with .NET I'd suggest you consider creating a DLL in .NET that you can call from Access, and then use that ...

    Author Comment

    Ok..this is starting to make Scott, I've steered clear of .net until this point.
    At my age, by the time I learn .net it I probably won't have enough years left to use it... Perhaps that why I'm still using Access 2k!

    Jim, your code makes much more sense now.. I will try it as soon as I get my eBay token... A few questions though...

    I already have a reference to Microsoft XML 2.0 lib, so I must have added that for some routine at one time.  Would you replace 2.0 w/ 6.0 and cross your fingers?

    Does it look to you like the cvs file should be embedded in the string, or would you think just the path to the file is what they want?

    The eBay code uses double quotes. Would you change them to single quotes or use the chr(34) character?
    LVL 56

    Expert Comment

    by:Jim Dettman (Microsoft MVP/ EE MVE)
    <<I already have a reference to Microsoft XML 2.0 lib, so I must have added that for some routine at one time.  Would you replace 2.0 w/ 6.0 and cross your fingers?>>

      Yes on the first, no on the last.   First, do a compile of your existing project.  Make sure there are no errors.   Then remove the 2.0 reference.   Again compile.   No Errors?  Then your set...nothing in the existing project relies on that.

      If you do get errors, now set the reference to version 6.  Compile errors?  You *may* be set.  You'll need to test the existing code to see if it works the same.  If errors, then something has changed between ver 2 and 6.

      With all that said, I don't know that the code I posted will not work with ver 2.0, but I would use 6.  2.0 must be quite old by this point.

    <<Does it look to you like the cvs file should be embedded in the string, or would you think just the path to the file is what they want?>>

     Looks to me like they want the contents of the file in the string, but I didn't look at the docs, just the code you posted in the question.

    LVL 44

    Expert Comment

    by:Martin Liss
    I've requested that this question be deleted for the following reason:

    Not enough information to confirm an answer.
    LVL 56

    Expert Comment

    by:Jim Dettman (Microsoft MVP/ EE MVE)
    Scott was first to the plate with a correct answer and I was a close second.

    LVL 84
    Agreed - accept my first comment and Jim's first comment as the solution.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
    You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    737 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

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now