public void DoAccountQuery() { bool sessionBegun = false; bool connectionOpen = false; QBSessionManager sessionManager = null; QBSessionMgr QBMgr = null; try { //Create the session Manager object QBMgr = new QBSessionMgr(); QBMgr.CreateQBSession(out sessionManager); // Get the RequestMsgSet based on the correct QB Version IMsgSetRequest requestMsgSet = QBMgr.getLatestMsgSetRequest(sessionManager); requestMsgSet.Attributes.OnError = ENRqOnError.roeContinue; // BuildAccountQueryRq(requestMsgSet); IAccountQuery AccountQueryRq = requestMsgSet.AppendAccountQueryRq(); // Uncomment the following to view and save the request and response XML // string requestXML = requestSet.ToXMLString(); // MessageBox.Show(requestXML); //Send the request and get the response from QuickBooks IMsgSetResponse responseMsgSet = sessionManager.DoRequests(requestMsgSet); string responseXML = responseMsgSet.ToXMLString(); //MessageBox.Show(responseXML); WalkAccountQueryRs(responseMsgSet); //End the session and close the connection to QuickBooks //Close the session and connection with QuickBooks QBMgr.CloseQBConnection(sessionManager); } catch (Exception ex) { // MessageBox.Show(e.Message, "Error"); // MessageBox.Show(ex.Message.ToString() + "\nStack Trace: \n" + ex.StackTrace + "\nExiting the application"); if (sessionBegun) { sessionManager.EndSession(); } if (connectionOpen) { sessionManager.CloseConnection(); } } finally { QBMgr.CloseQBConnection(sessionManager); } }
public IResponseList GetQBAccountInfo(QBSessionManager sessionManager) { //bool sessionBegun = false; //bool connectionOpen = false; QBSession QBMgr = null; IResponseList responseList = null; try { QBMgr = new QBSession(); if (sessionManager == null) { //Create the session Manager object QBMgr.CreateQBSession(out sessionManager); } // Get the RequestMsgSet based on the correct QB Version IMsgSetRequest requestMsgSet = QBMgr.getLatestMsgSetRequest(sessionManager); requestMsgSet.Attributes.OnError = ENRqOnError.roeContinue; // BuildAccountQueryRq(requestMsgSet); IAccountQuery AccountQueryRq = requestMsgSet.AppendAccountQueryRq(); //Send the request and get the response from QuickBooks IMsgSetResponse responseMsgSet = sessionManager.DoRequests(requestMsgSet); if (responseMsgSet == null) { return(null); } responseList = responseMsgSet.ResponseList; if (responseList == null) { return(null); } //WalkAccountQueryRs(responseMsgSet); //End the session and close the connection to QuickBooks //Close the session and connection with QuickBooks //QBMgr.CloseQBConnection(sessionManager); } catch (Exception ex) { } finally { } return(responseList); }
///<summary>Adds an account query to the request message. A QB connection must be open before calling this method. Requires connection with version 8.0</summary> private static void QueryListOfAccounts() { if (!ConnectionOpen) { return; } //Build the account query add append it to the request message. IAccountQuery AccountQueryRq = RequestMsgSet.AppendAccountQueryRq(); //Filters AccountQueryRq.ORAccountListQuery.AccountListFilter.ActiveStatus.SetValue(ENActiveStatus.asActiveOnly); }
/// <summary> /// The GetQBAccounts. /// </summary> /// <param name="logsFile">The logsFile<see cref="StreamWriter"/>.</param> /// <returns>The <see cref="List{dynamic}"/>.</returns> public List <dynamic> GetQBAccounts(StreamWriter logsFile) { IMsgSetRequest requestSet = SessionManager.Instance.CreateMsgSetRequest(); requestSet.Attributes.OnError = ENRqOnError.roeStop; requestSet.AppendAccountQueryRq(); IMsgSetResponse responeSet = SessionManager.Instance.DoRequests(requestSet, logsFile); IResponseList responseList = responeSet.ResponseList; List <dynamic> accountsArray = new List <dynamic>(); var account_number = ""; try { for (int i = 0; i < responseList.Count; i++) { IResponse response = responseList.GetAt(i); if (response.StatusCode == 0) { IAccountRetList AccountRet = (IAccountRetList)response.Detail; Console.WriteLine("Number Of Records Being Fetched Are:\t" + AccountRet.Count + "\n"); for (int j = 0; j < AccountRet.Count; j++) { IAccountRet account = AccountRet.GetAt(j); if (account.AccountNumber != null) { account_number = account.AccountNumber.GetValue(); } else { account_number = "Account Number Not Defined..."; } accountsArray.Add(new string[] { account.Name.GetValue().ToString(), account_number, account.AccountType.GetValue().ToString(), account.TotalBalance.GetValue().ToString() }); } } } } catch (Exception ex) { logsFile.WriteLine(DateTime.Now + "\tERROR\tError Message:\t" + ex.Message); logsFile.WriteLine(); logsFile.WriteLine(DateTime.Now + "\tERROR\tError Message:\tStack Trace:\t" + ex.StackTrace); logsFile.WriteLine(); } return(accountsArray); }
/// <summary> /// Obtain a list of all QuickBooks accounts. /// </summary> /// <returns>a list of quickbooks accounts</returns> private List <QuickbooksAccount> getAccounts(ENAccountType type) { List <QuickbooksAccount> account = new List <QuickbooksAccount>(); IMsgSetRequest msgRequest = qbMgr.CreateMsgSetRequest("US", 4, 0); msgRequest.Attributes.OnError = ENRqOnError.roeStop; IAccountQuery query = msgRequest.AppendAccountQueryRq(); query.ORAccountListQuery.AccountListFilter.AccountTypeList.Add(type); IMsgSetResponse response = qbMgr.DoRequests(msgRequest); IAccountRetList qbAccounts = (IAccountRetList)response.ResponseList.GetAt(0).Detail; for (int i = 0; qbAccounts != null && i < qbAccounts.Count; i++) { account.Add(new QuickbooksAccount() { Name = qbAccounts.GetAt(i).FullName.GetValue() }); } return(account); }
void BuildAccountQueryRq(IMsgSetRequest requestMsgSet) { IAccountQuery AccountQueryRq = requestMsgSet.AppendAccountQueryRq(); //Set attributes //Set field value for metaData AccountQueryRq.metaData.SetValue(ENmetaData.mdMetaDataAndResponseData); //"IQBENmetaDataType" string ORAccountListQueryElementType433 = "ListIDList"; if (ORAccountListQueryElementType433 == "ListIDList") { //Set field value for ListIDList //May create more than one of these if needed // AccountQueryRq.ORAccountListQuery.ListIDList.Add("80000002-1552559344"); } if (ORAccountListQueryElementType433 == "FullNameList") { //Set field value for FullNameList //May create more than one of these if needed // AccountQueryRq.ORAccountListQuery.FullNameList.Add("CML01"); } if (ORAccountListQueryElementType433 == "AccountListFilter") { //Set field value for MaxReturned AccountQueryRq.ORAccountListQuery.AccountListFilter.MaxReturned.SetValue(6); //Set field value for ActiveStatus AccountQueryRq.ORAccountListQuery.AccountListFilter.ActiveStatus.SetValue(ENActiveStatus.asActiveOnly); //Set field value for FromModifiedDate AccountQueryRq.ORAccountListQuery.AccountListFilter.FromModifiedDate.SetValue(DateTime.Now, false); //Set field value for ToModifiedDate AccountQueryRq.ORAccountListQuery.AccountListFilter.ToModifiedDate.SetValue(DateTime.Now, false); string ORNameFilterElementType434 = "NameFilter"; if (ORNameFilterElementType434 == "NameFilter") { //Set field value for MatchCriterion // AccountQueryRq.ORAccountListQuery.AccountListFilter.ORNameFilter.NameFilter.MatchCriterion.SetValue(ENMatchCriterion.mcStartsWith); //Set field value for Name //AccountQueryRq.ORAccountListQuery.AccountListFilter.ORNameFilter.NameFilter.Name.SetValue("CML01"); } if (ORNameFilterElementType434 == "NameRangeFilter") { //Set field value for FromName // AccountQueryRq.ORAccountListQuery.AccountListFilter.ORNameFilter.NameRangeFilter.FromName.SetValue("CML01"); //Set field value for ToName //AccountQueryRq.ORAccountListQuery.AccountListFilter.ORNameFilter.NameRangeFilter.ToName.SetValue("CML01"); } //Set field value for AccountTypeList //May create more than one of these if needed AccountQueryRq.ORAccountListQuery.AccountListFilter.AccountTypeList.Add(ENAccountType.atAccountsReceivable); //ENAccountTypeList.atlAccountsPayable string ORCurrencyFilterElementType435 = "ListIDList"; if (ORCurrencyFilterElementType435 == "ListIDList") { //Set field value for ListIDList //May create more than one of these if needed // AccountQueryRq.ORAccountListQuery.AccountListFilter.CurrencyFilter.ORCurrencyFilter.ListIDList.Add("200000-1011023419"); } if (ORCurrencyFilterElementType435 == "FullNameList") { //Set field value for FullNameList //May create more than one of these if needed //AccountQueryRq.ORAccountListQuery.AccountListFilter.CurrencyFilter.ORCurrencyFilter.FullNameList.Add("CML01"); } } //Set field value for IncludeRetElementList //May create more than one of these if needed //AccountQueryRq.IncludeRetElementList.Add("CML01"); //Set field value for OwnerIDList //May create more than one of these if needed //AccountQueryRq.OwnerIDList.Add(Guid.NewGuid().ToString("B")); }