1

(18 replies, posted in OFX Spec)

Yeah, does not seem to work for me either.

2

(1 replies, posted in OFX Tools)

From the spec the syntax is <INCTRANIMG>Y</INCTRANIMG> however including this in my STMTRQ i get a 400 bad request.. :-\

3

(18 replies, posted in OFX Spec)

Wow totally missed the download spec link at ofx.net

http://ofx.net/DownloadPage/Downloads.aspx

will be studying this now

4

(18 replies, posted in OFX Spec)

Very cool , I appreciate the feedback & updates!

edit: I'm interested in expanding this code to include more features of the OFX protocol but unfortunately I cant really find any good source of the specification of this protocol w/ examples. My next would be to retrieve check images from the bank. If you have any information or valuable resources for OFX spec definitely let me know. I will be checking back here routinely to keep up to date with this stuff. Thanks again

5

(18 replies, posted in OFX Spec)

Here is a more complete version which fixes the account request and also parses the information for you and stores the data in easy to use collection objects.

   Public Structure _BankItem
        Dim ItemType As String
        Dim DatePosted As String
        Dim ItemAmount As String
        Dim FITID As String
        Dim CheckNumber As String
        Dim Memo As String
        Dim ItemName As String

    End Structure
    Public Structure _AccountListInfo
        Dim AccountName As String
        Dim BankID As String
        Dim AccountID As String
        Dim AccountType As String
        Dim Status As String
    End Structure
    Public Class OFXDownload
        Dim objReq As HttpWebRequest
        Dim DataBuffer As New StringBuilder
        Dim ReqStream As IO.Stream
        Dim _ResponseString As String
        Dim objResponse As HttpWebResponse
        Dim ResponseStream As IO.Stream
        Dim CurrGuid As String
        Dim _UserName As String
        Dim _Password As String
        Dim _BankItemCollection As New Collection(Of _BankItem)
        Dim _LedgerBalance As String
        Dim _AvailableBalance As String
        Dim _RequestType As RequestType
        Dim _AccountListCollection As New Collection(Of _AccountListInfo)



        Public Enum RequestType
            AccountList = 0
            AccountActivity = 1
        End Enum
        Public ReadOnly Property AccountListCollection() As Collection(Of _AccountListInfo)
            Get
                AccountListCollection = _AccountListCollection
            End Get
        End Property
        Public ReadOnly Property BankItemCollection() As Collection(Of _BankItem)
            Get
                BankItemCollection = _BankItemCollection
            End Get
        End Property
        Public ReadOnly Property LedgerBalance() As String
            Get
                LedgerBalance = _LedgerBalance
            End Get
        End Property
        Public ReadOnly Property AvailableBalance() As String
            Get
                AvailableBalance = _AvailableBalance
            End Get
        End Property
        Public Sub New(ByVal ofx_RequestType As RequestType, ByVal userName As String, ByVal password As String, ByVal AccountID As String, ByVal BankID As String, ByVal org As String, ByVal FID As String)

            _UserName = userName
            _Password = password
            CurrGuid = Guid.NewGuid.ToString
            Dim clientDate As String
            clientDate = Format(DateTime.Now, "yyyyMMddHHmmss")



            DataBuffer.AppendLine("OFXHEADER:100")
            DataBuffer.AppendLine("DATA:OFXSGML")
            DataBuffer.AppendLine("VERSION:102")
            DataBuffer.AppendLine("SECURITY:NONE")
            DataBuffer.AppendLine("ENCODING:USASCII")
            DataBuffer.AppendLine("CHARSET:1252")
            DataBuffer.AppendLine("COMPRESSION:NONE")
            DataBuffer.AppendLine("OLDFILEUID:NONE")
            DataBuffer.AppendLine("NEWFILEUID:NONE")
            DataBuffer.AppendLine()
            DataBuffer.AppendLine("<OFX>")
            DataBuffer.AppendLine("<SIGNONMSGSRQV1>")
            DataBuffer.AppendLine("<SONRQ>")
            DataBuffer.AppendLine("<DTCLIENT>" & clientDate)
            DataBuffer.AppendLine("<USERID>" & userName)
            DataBuffer.AppendLine("<USERPASS>" & password)
            DataBuffer.AppendLine("<LANGUAGE>ENG")
            DataBuffer.AppendLine("<FI>")
            DataBuffer.AppendLine("<ORG>" & org)
            DataBuffer.AppendLine("<FID>" & FID)
            DataBuffer.AppendLine("</FI>")
            DataBuffer.AppendLine("<APPID>QWIN")
            DataBuffer.AppendLine("<APPVER>0900")
            DataBuffer.AppendLine("</SONRQ>")
            DataBuffer.AppendLine("</SIGNONMSGSRQV1>")
            _RequestType = ofx_RequestType
            Select Case ofx_RequestType
                Case RequestType.AccountList
                    DataBuffer.AppendLine("<SIGNUPMSGSRQV1>")
                    DataBuffer.AppendLine("<ACCTINFOTRNRQ>")
                    DataBuffer.AppendLine("<TRNUID>" & CurrGuid)
                    DataBuffer.AppendLine("<CLTCOOKIE>4")
                    DataBuffer.AppendLine("<ACCTINFORQ>")
                    DataBuffer.AppendLine("<DTACCTUP>19700101000000")
                    DataBuffer.AppendLine("</ACCTINFORQ>")
                    DataBuffer.AppendLine("</ACCTINFOTRNRQ>")
                    DataBuffer.AppendLine("</SIGNUPMSGSRQV1>")
                    DataBuffer.AppendLine("</OFX>")
                Case RequestType.AccountActivity
                    DataBuffer.Append("<BANKMSGSRQV1>")
                    DataBuffer.Append("<STMTTRNRQ>")
                    DataBuffer.Append("<TRNUID>" & CurrGuid)
                    DataBuffer.Append("<STMTRQ>")
                    DataBuffer.Append("<BANKACCTFROM>")
                    DataBuffer.Append("<BANKID>" & BankID)
                    DataBuffer.Append("<ACCTID>" & AccountID)
                    DataBuffer.Append("<ACCTTYPE>CHECKING")
                    DataBuffer.Append("</BANKACCTFROM>")
                    DataBuffer.Append("<INCTRAN>")
                    DataBuffer.Append("<INCLUDE>Y")
                    DataBuffer.Append("</INCTRAN>")
                    DataBuffer.Append("</STMTRQ>")
                    DataBuffer.Append("</STMTTRNRQ>")
                    DataBuffer.Append("</BANKMSGSRQV1>")
                    DataBuffer.Append("</OFX>")

                    'later
            End Select
        End Sub
        Public Function Download() As String
            Dim byteBuffer() As Byte = Encoding.ASCII.GetBytes(DataBuffer.ToString)
            Dim responseReader As StreamReader


            objReq = WebRequest.Create("https://ofx.chase.com")
            objReq.Method = "POST"
            objReq.ContentType = "application/x-ofx"
            objReq.Accept = "*/*, application/x-ofx"
            objReq.ContentLength = byteBuffer.Length
            System.Net.ServicePointManager.Expect100Continue = False
            ReqStream = objReq.GetRequestStream
            ReqStream.Write(byteBuffer, 0, byteBuffer.Length)
            ReqStream.Close()
            objResponse = objReq.GetResponse

            ResponseStream = objReq.GetResponse.GetResponseStream
            responseReader = New StreamReader(ResponseStream)
            _ResponseString = responseReader.ReadToEnd
            Select Case _RequestType
                Case RequestType.AccountActivity
                    ParseBankItems()
                Case RequestType.AccountList
                    ParseAccountList()
            End Select

            Return _ResponseString


        End Function
        Private Sub ParseAccountList()
            _AccountListCollection.Clear()
            Dim AccountName As String
            Dim BankID As String
            Dim AccountID As String
            Dim AccountType As String
            Dim Status As String

            Dim MyAccountInfo As _AccountListInfo

            Dim AccntInfoList() As String = Split(_ResponseString, "<ACCTINFO>")
            For Each Account As String In AccntInfoList
                If InStr(Account, "<DESC>") Then
                    'This is an account item
                    MyAccountInfo.AccountID = ""
                    MyAccountInfo.AccountName = ""
                    MyAccountInfo.AccountType = ""
                    MyAccountInfo.BankID = ""
                    MyAccountInfo.Status = ""

                    AccountName = Split(Account, "<DESC>")(1)
                    AccountName = AccountName.Substring(0, AccountName.IndexOf("<"))
                    MyAccountInfo.AccountName = AccountName

                    BankID = Split(Account, "<BANKID>")(1)
                    BankID = BankID.Substring(0, BankID.IndexOf("<"))
                    MyAccountInfo.BankID = BankID

                    AccountID = Split(Account, "<ACCTID>")(1)
                    AccountID = AccountID.Substring(0, AccountID.IndexOf("<"))
                    MyAccountInfo.AccountID = AccountID

                    AccountType = Split(Account, "<ACCTTYPE>")(1)
                    AccountType = AccountType.Substring(0, AccountType.IndexOf("<"))
                    MyAccountInfo.AccountType = AccountType

                    Status = Split(Account, "<SVCSTATUS>")(1)
                    Status = Status.Substring(0, Status.IndexOf("<"))
                    MyAccountInfo.Status = Status
                    _AccountListCollection.Add(MyAccountInfo)

                End If
            Next
        End Sub
        Private Sub ParseBankItems()
            _BankItemCollection.Clear()
            Dim TransactionType As String
            Dim DatePosted As String
            Dim Amount As String
            Dim FITID As String
            Dim Memo As String
            Dim CheckNumber As String
            Dim ItemName As String
            Dim MyTransaction As _BankItem
            Dim BankTransList() As String
            BankTransList = Split(_ResponseString, "<BANKTRANLIST>")
            Dim TransactionList() As String
            TransactionList = Split(BankTransList(1), "<STMTTRN>")
            Dim LedgerBal() As String = Split(_ResponseString, "<LEDGERBAL>")
            _LedgerBalance = Split(LedgerBal(1), "<BALAMT>")(1)
            _LedgerBalance = _LedgerBalance.Substring(0, _LedgerBalance.IndexOf("<"))
            Dim AvailBal() As String = Split(_ResponseString, "<AVAILBAL>")
            _AvailableBalance = Split(AvailBal(1), "<BALAMT>")(1)
            _AvailableBalance = _AvailableBalance.Substring(0, _AvailableBalance.IndexOf("<"))

            For Each Transaction As String In TransactionList
                If InStr(Transaction, "TRNTYPE") Then
                    MyTransaction.CheckNumber = ""
                    MyTransaction.DatePosted = ""
                    MyTransaction.FITID = ""
                    MyTransaction.ItemAmount = ""
                    MyTransaction.ItemName = ""
                    MyTransaction.ItemType = ""
                    MyTransaction.Memo = ""

                    'This is a transaction

                    TransactionType = Split(Transaction, "<TRNTYPE>")(1)
                    TransactionType = TransactionType.Substring(0, TransactionType.IndexOf("<"))

                    MyTransaction.ItemType = TransactionType

                    DatePosted = Split(Transaction, "<DTPOSTED>")(1)
                    DatePosted = DatePosted.Substring(0, DatePosted.IndexOf("<"))
                    DatePosted = DatePosted.Substring(0, 8)
                    DatePosted = DatePosted.Substring(4, 2) & "/" & DatePosted.Substring(6, 2) & "/" & DatePosted.Substring(0, 4)
                    MyTransaction.DatePosted = DatePosted

                    Amount = Split(Transaction, "<TRNAMT>")(1)
                    Amount = Amount.Substring(0, Amount.IndexOf("<"))

                    MyTransaction.ItemAmount = Amount

                    FITID = Split(Transaction, "<FITID>")(1)
                    FITID = FITID.Substring(0, FITID.IndexOf("<"))
                    MyTransaction.FITID = FITID
                    If InStr(Transaction, "<CHECKNUM>") Then 'its a check
                        CheckNumber = Split(Transaction, "<CHECKNUM>")(1)
                        CheckNumber = CheckNumber.Substring(0, CheckNumber.IndexOf("<"))
                        MyTransaction.CheckNumber = CheckNumber
                    End If
                    If InStr(Transaction, "<MEMO>") Then 'It has a memo
                        Memo = Split(Transaction, "<MEMO>")(1)
                        Memo = Memo.Substring(0, Memo.IndexOf("<"))
                        MyTransaction.Memo = Memo
                    End If
                    ItemName = Split(Transaction, "<NAME>")(1)
                    ItemName = ItemName.Substring(0, ItemName.IndexOf("<"))
                    MyTransaction.ItemName = ItemName


                    _BankItemCollection.Add(MyTransaction)

                End If
            Next
        End Sub
        
        Public ReadOnly Property ResponseString() As String
            Get
                ResponseString = _ResponseString
            End Get
        End Property
    End Class

Feel free to improve & use and thanks for running a very informative website for information that is not so easily attainable. This is my gift back. Oh yea, also i've only tested this with chase so I have no idea how it will work on other ofx servers.

6

(18 replies, posted in OFX Spec)

Thankyou sir!

7

(18 replies, posted in OFX Spec)

Greetings, I created this today and I know its kind of incomplete but i've gotten it to basically work for me. I wanted one that could do Chase for my company and the financial software im developing for them. I will post the source code free on here for others to examine and learn with. As far as I know this is the only example i've found for accessing OFX Direct connect in the .NET. For the "Account Activity" porition I copied the OFX spec directly from the OFX website in their banking example. I still cannot get the Account List request to work I get a 400 bad request any help on that would be appreciated. Without further ado here it is.

    Public Class OFXDownload
        Dim objReq As HttpWebRequest
        Dim DataBuffer As New StringBuilder
        Dim ReqStream As IO.Stream
        Dim _ResponseString As String
        Dim objResponse As HttpWebResponse
        Dim ResponseStream As IO.Stream
        Dim CurrGuid As String
        Dim _UserName As String
        Dim _Password As String

        Public Enum RequestType
            AccountList = 0
            AccountActivity = 1
        End Enum
        Public Sub New(ByVal ofx_RequestType As RequestType, ByVal userName As String, ByVal password As String, ByVal AccountID As String, ByVal BankID As String, ByVal org As String, ByVal FID As String)

            _UserName = userName
            _Password = password
            CurrGuid = Guid.NewGuid.ToString
            Dim clientDate As String
            clientDate = Format(DateTime.Now, "yyyyMMddHHmmss")



            DataBuffer.AppendLine("OFXHEADER:100")
            DataBuffer.AppendLine("DATA:OFXSGML")
            DataBuffer.AppendLine("VERSION:102")
            DataBuffer.AppendLine("SECURITY:NONE")
            DataBuffer.AppendLine("ENCODING:USASCII")
            DataBuffer.AppendLine("CHARSET:1252")
            DataBuffer.AppendLine("COMPRESSION:NONE")
            DataBuffer.AppendLine("OLDFILEUID:NONE")
            DataBuffer.AppendLine("NEWFILEUID:NONE")
            DataBuffer.AppendLine()
            DataBuffer.AppendLine("<OFX>")
            DataBuffer.AppendLine("<SIGNONMSGSRQV1>")
            DataBuffer.AppendLine("<SONRQ>")
            DataBuffer.AppendLine("<DTCLIENT>" & clientDate)
            DataBuffer.AppendLine("<USERID>" & userName)
            DataBuffer.AppendLine("<USERPASS>" & password)
            DataBuffer.AppendLine("<LANGUAGE>ENG")
            DataBuffer.AppendLine("<FI>")
            DataBuffer.AppendLine("<ORG>" & org)
            DataBuffer.AppendLine("<FID>" & FID)
            DataBuffer.AppendLine("</FI>")
            DataBuffer.AppendLine("<APPID>QWIN")
            DataBuffer.AppendLine("<APPVER>0900")
            DataBuffer.AppendLine("</SONRQ>")
            DataBuffer.AppendLine("</SIGNONMSGSRQV1>")

            Select Case ofx_RequestType
                Case RequestType.AccountList
                    DataBuffer.AppendLine("<SIGNUPMSGSRQV1>")
                    DataBuffer.AppendLine("<ACCTINFOTRNRQ>")
                    DataBuffer.AppendLine("<ACCTINFORQ>")
                    DataBuffer.AppendLine("<DTACCTUP>19700101000000")
                    DataBuffer.AppendLine("</ACCTINFORQ>")
                    DataBuffer.AppendLine("</ACCTINFOTRNRQ>")
                    DataBuffer.AppendLine("</SIGNUPMSGSRQV1>")
                    DataBuffer.AppendLine("</OFX>")
                Case RequestType.AccountActivity
                    DataBuffer.Append("<BANKMSGSRQV1>")
                    DataBuffer.Append("<STMTTRNRQ>")
                    DataBuffer.Append("<TRNUID>" & CurrGuid)
                    DataBuffer.Append("<STMTRQ>")
                    DataBuffer.Append("<BANKACCTFROM>")
                    DataBuffer.Append("<BANKID>" & BankID)
                    DataBuffer.Append("<ACCTID>" & AccountID)
                    DataBuffer.Append("<ACCTTYPE>CHECKING")
                    DataBuffer.Append("</BANKACCTFROM>")
                    DataBuffer.Append("<INCTRAN>")
                    DataBuffer.Append("<INCLUDE>Y")
                    DataBuffer.Append("</INCTRAN>")
                    DataBuffer.Append("</STMTRQ>")
                    DataBuffer.Append("</STMTTRNRQ>")
                    DataBuffer.Append("</BANKMSGSRQV1>")
                    DataBuffer.Append("</OFX>")

                    'later
            End Select
        End Sub
        Public Function Download() As String
            MsgBox(DataBuffer.ToString)
            Dim byteBuffer() As Byte = Encoding.ASCII.GetBytes(DataBuffer.ToString)
            Dim responseReader As StreamReader

            objReq = WebRequest.Create("https://ofx.chase.com")
            objReq.Method = "POST"
            objReq.ContentType = "application/x-ofx"
            objReq.Accept = "*/*, application/x-ofx"
            objReq.ContentLength = byteBuffer.Length
            System.Net.ServicePointManager.Expect100Continue = False
            ReqStream = objReq.GetRequestStream
            ReqStream.Write(byteBuffer, 0, byteBuffer.Length)
            ReqStream.Close()
            objResponse = objReq.GetResponse

            ResponseStream = objReq.GetResponse.GetResponseStream
            responseReader = New StreamReader(ResponseStream)
            _ResponseString = responseReader.ReadToEnd
            Return _ResponseString


        End Function
        Public ReadOnly Property ResponseString()
            Get
                ResponseString = _ResponseString
            End Get
        End Property
    End Class

and an example of how to use:

Dim MyOFXData as new OFXDownload(OFXDownload.RequestType.AccountActivity,"username","password","ACCOUNTID","BANKID","ORG","FID")
MessageBox.show(MyOFXData.Download)

This will return in string format the OFX Data. Parsing it is of course up to you.