hellfire45
Active Member
- Joined
- Jun 7, 2014
- Messages
- 464
So somebody at my company has told me they would like a macro enabled Excel workbook that can connect to a certain Fortune 100 Electronics company's database system via API and extract customer requested information. A customer would be able to enter a quote # or some other UID and it will connect to their database system and extract data pertaining to product orders.
An API has been created to do this and I have API documentation for XML integration.
Has anybody ever done anything like this?
Any advice? Online resources? Any info needed from the manual that might help?
I'm not really sure how to get started.
Some info below from the XML Integration Manual:
Basic Coding Overview
This section will not cover the programmatic creation of the submit XML document, there are many utilities available in a variety of languages that facilitate this processing. Nor will this section cover the accessing and navigation through the response XML document, again, many utilities and practices are available.
Once the submit document is created the following steps should be taken by your automated process:
An API has been created to do this and I have API documentation for XML integration.
Has anybody ever done anything like this?
Any advice? Online resources? Any info needed from the manual that might help?
I'm not really sure how to get started.
Some info below from the XML Integration Manual:
Basic Coding Overview
This section will not cover the programmatic creation of the submit XML document, there are many utilities available in a variety of languages that facilitate this processing. Nor will this section cover the accessing and navigation through the response XML document, again, many utilities and practices are available.
Once the submit document is created the following steps should be taken by your automated process:
- If necessary, convert the XML document to a String representation
- Establish an HTTP connection to company's XML service
- Set the HTTP's header property "Content-Type" to a value of "text/xml"
- Set the HTTP's header property "Content-Length" to the exact length of your submit XML document's string representation
- Post the XML document, as a string, through the HTTP connection from step 2 above
- Obtain a response stream from the HTTP connection
- Receive the response XML document as a string
Code:
[B]VB.Net Example[/B]
The following VB.Net code snippet was written in version 1.1[INDENT][INDENT][COLOR=#008000]' xmlDocAsStr is the submit XML document as a String[/COLOR]
Dim byteArray(xmlDocAsStr.Length - 1) As Byte
Dim objUTF8Encoding As New UTF8Encoding
byteArray = objUTF8Encoding.GetBytes(xmlDocAsStr)
[COLOR=#008000]' urlStr is companyURL as a String[/COLOR]
Dim con As CType(WebRequest.Create(urlStr), HttpWebRequest)
con.Method = "POST"
con.ContentType = "text/xml"
con.ContentLength = byteArray.Length
Dim strmRequest As con.GetRequestStream()
strmRequest.Write(byteArray, 0, byteArray.Length) [COLOR=#008000]' send the submit xml document[/COLOR]
strmRequest.Close()
Dim srResponse as New StreamReader(con.GetResponse().GetResponseStream(), Encoding.ASCII)
Dim sb as srResponse.ReadToEnd() [COLOR=#008000] ' receive the response xml document[/COLOR]
[COLOR=#008000]' the response XML document is now in sb as a String[/COLOR]
[/INDENT]
[/INDENT]
srResponse.Close() [COLOR=#008000]' ALWAYS close your connection ![/COLOR]