Perform HTTP Post from within Excel and Parse Results

Scott picture Scott · Nov 30, 2009 · Viewed 47.3k times · Source

I have access to an API. The API takes an XML post as input and then returns an XML response with the relevant data.

I want to

  1. Send the HTTP Post to the Server (Authentication and Request will be sent together)
  2. Receive the response (One of the options to be returned is CSV or XML)
  3. Insert the data into the appropriate rows and columns and then perform data analysis using pivot tables.

I don't have a programming background in excel but am comfortable with different web scripting languages, HTML, CSS, Javascript etc.

Any ideas?

Answer

Robert Mearns picture Robert Mearns · Nov 30, 2009

The Excel request side can be handled with this VBA code.

Sub GetStuff()

Dim objXML As Object
Dim strData As String
Dim strResponse As String

 strData = "Request"
 Set objXML = CreateObject("MSXML2.XMLHTTP")

 objXML.Open "POST", "www.example.com/api?" & strData, False
 objXML.Send
 strResponse = objXML.responsetext

MsgBox strResponse

End Sub