public void batchtestall() { ServiceContext context = Initializer.InitializeServiceContextQbo(); DataService service = new DataService(context); Customer customer1 = new Customer(); string guid = Guid.NewGuid().ToString("n"); customer1.GivenName = guid.Substring(0, 25); string GivenNameCustomer1 = customer1.GivenName; customer1.Title = guid.Substring(0, 15); customer1.MiddleName = guid.Substring(0, 5); customer1.FamilyName = guid.Substring(0, 25); customer1.DisplayName = guid.Substring(0, 20); Customer customer2 = new Customer(); guid = Guid.NewGuid().ToString("n"); customer2.GivenName = guid.Substring(0, 25); string GivenNameCustomer2 = customer2.GivenName; customer2.Title = guid.Substring(0, 15); customer2.MiddleName = guid.Substring(0, 5); customer2.FamilyName = guid.Substring(0, 25); customer2.DisplayName = guid.Substring(0, 20); try { Batch batch = service.CreateNewBatch(); batch.Add(customer1, "addcustomer1", OperationEnum.create); batch.Add(customer2, "addcustomer2", OperationEnum.create); batch.Add("select * from Customer startPosition 0 maxResults 10", "queryCustomer"); batch.Execute(); IntuitBatchResponse inuititemresponse = batch.IntuitBatchItemResponses[0]; Assert.IsTrue(inuititemresponse.ResponseType == ResponseType.Entity); Customer resultcustomer1 = inuititemresponse.Entity as Customer; Assert.IsFalse(string.IsNullOrEmpty(resultcustomer1.Id)); Assert.IsTrue(resultcustomer1.GivenName == GivenNameCustomer1); inuititemresponse = batch.IntuitBatchItemResponses[1]; Assert.IsTrue(inuititemresponse.ResponseType == ResponseType.Entity); Customer resultcustomer2 = inuititemresponse.Entity as Customer; Assert.IsFalse(string.IsNullOrEmpty(resultcustomer2.Id)); Assert.IsTrue(resultcustomer2.GivenName == GivenNameCustomer2); inuititemresponse = batch.IntuitBatchItemResponses[2]; Assert.IsTrue(inuititemresponse.ResponseType == ResponseType.Query); List <Customer> customers = inuititemresponse.Entities.ToList().ConvertAll(item => item as Customer); Assert.IsTrue(customers.Count >= 2); } catch (Ipp.Exception.IdsException ex) { Assert.Fail(ex.ToString()); } }
public void BatchIncludeTest() { ServiceContext context = Initializer.InitializeQBOServiceContextUsingoAuth(); DataService.DataService service = new DataService.DataService(context); DataService.Batch batch = service.CreateNewBatch(); List <String> optionsData = new List <string>(); optionsData.Add("firsttxndate"); batch.Add("Select * From CompanyInfo", "QueryCo", optionsData); batch.Execute(); bool receivedIncludeParameter = false; IntuitBatchResponse queryCompanyResponse = batch["QueryCo"]; if (queryCompanyResponse.ResponseType == ResponseType.Query) { CompanyInfo companyInfo = queryCompanyResponse.Entities[0] as CompanyInfo; foreach (NameValue nameValue in companyInfo.NameValue) { receivedIncludeParameter = nameValue.Name == "firsttxndate"; if (receivedIncludeParameter) { break; } } } if (!receivedIncludeParameter) { Assert.Fail("CompanyInfo not returned"); } }
public void BatchTest() { string accessTokenQBO = ConfigurationManager.AppSettings["AccessTokenQBO"]; string accessTokenSecretQBO = ConfigurationManager.AppSettings["AccessTokenSecretQBO"]; string consumerKeyQBO = ConfigurationManager.AppSettings["ConsumerKeyQBO"]; string ConsumerSecretQBO = ConfigurationManager.AppSettings["ConsumerSecretQBO"]; string realmIAQBO = ConfigurationManager.AppSettings["RealmIAQBO"]; OAuthRequestValidator oAuthRequestValidator = new OAuthRequestValidator(accessTokenQBO, accessTokenSecretQBO, consumerKeyQBO, ConsumerSecretQBO); ServiceContext context = new ServiceContext(realmIAQBO, IntuitServicesType.QBO, oAuthRequestValidator); DataService service = new DataService(context); context.IppConfiguration.Message.Response.CompressionFormat = Intuit.Ipp.Core.Configuration.CompressionFormat.GZip; context.IppConfiguration.Message.Response.SerializationFormat = Intuit.Ipp.Core.Configuration.SerializationFormat.Json; Customer customer = new Customer(); string guid = Guid.NewGuid().ToString("N"); customer.GivenName = guid.Substring(0, 25); customer.Title = guid.Substring(0, 15); customer.MiddleName = guid.Substring(0, 5); customer.FamilyName = guid.Substring(0, 25); customer.DisplayName = guid.Substring(0, 20); try { Batch batch = service.CreateNewBatch(); batch.Add(customer, "addCustomer", OperationEnum.create); batch.Add(new CDCQuery() { ChangedSince = DateTime.Now.AddDays(-1), ChangedSinceSpecified = true, Entities = "Customer" }, "cdcOpration"); batch.Execute(); IntuitBatchResponse addCustomerResponse = batch.IntuitBatchItemResponses[0]; if (addCustomerResponse.ResponseType != ResponseType.Exception) { Customer addedcustomer = addCustomerResponse.Entity as Customer; Assert.IsNotNull(addedcustomer); Assert.IsFalse(string.IsNullOrEmpty(addedcustomer.Id)); } IntuitBatchResponse CDCQueryResponse = batch.IntuitBatchItemResponses[1]; if (CDCQueryResponse.ResponseType != ResponseType.Exception) { Dictionary <string, List <IEntity> > cdcCustomers = CDCQueryResponse.CDCResponse.entities; Assert.IsNotNull(cdcCustomers); Assert.IsTrue(cdcCustomers.Count > 0); foreach (KeyValuePair <string, List <IEntity> > entry in cdcCustomers) { Assert.IsTrue(entry.Value.ElementAt(0).GetType() == new Customer().GetType()); } } else { Assert.Fail(); } } catch (Ipp.Exception.IdsException ex) { Assert.Fail(ex.ToString()); } }
public void IntuitBatchResponsePropertiesTest() { IntuitBatchResponse response = new IntuitBatchResponse(); response.Exception = new Exception.IdsException(); response.Id = "addCustomer"; Assert.AreEqual(response.Id, "addCustomer"); Assert.ReferenceEquals(response.Exception, new Exception.IdsException()); }
public void RemoveItem() { Batch batch = GetBatch(); for (int i = 0; i <= 10; i++) { Customer customer = GetCustomer(); batch.Add(customer, "Customer" + i.ToString(), OperationEnum.create); } batch.Remove("Customer0"); IntuitBatchResponse item = batch["Customer0"] as IntuitBatchResponse; }
/// <summary> /// Test QBO api call /// </summary> public async System.Threading.Tasks.Task QboApiCall() { try { if ((dictionary.ContainsKey("accessToken")) && (dictionary.ContainsKey("realmId"))) { Output("Making QBO API Call."); OAuth2RequestValidator oauthValidator = new OAuth2RequestValidator(dictionary["accessToken"]); ServiceContext serviceContext = new ServiceContext(dictionary["realmId"], IntuitServicesType.QBO, oauthValidator); serviceContext.IppConfiguration.BaseUrl.Qbo = "https://sandbox-quickbooks.api.intuit.com/"; //serviceContext.IppConfiguration.BaseUrl.Qbo = "https://quickbooks.api.intuit.com/";//prod serviceContext.IppConfiguration.MinorVersion.Qbo = "29"; ReportService reportService = new ReportService(serviceContext); //Date should be in the format YYYY-MM-DD //Response format hsold be JSON as that is pnly supported rigth now for reports reportService.accounting_method = "Accrual"; reportService.start_date = "2018-01-01"; reportService.end_date = "2018-07-01"; ////reportService.classid = "2800000000000634813"; //reportService.date_macro = "Last Month"; reportService.summarize_column_by = "Month"; //List<String> columndata = new List<String>(); //columndata.Add("tx_date"); //columndata.Add("dept_name"); //string coldata = String.Join(",", columndata); //reportService.columns = coldata; var report1 = reportService.ExecuteReport("TrialBalance"); DataService commonServiceQBO = new DataService(serviceContext); //Item item = new Item(); //List<Item> results = commonServiceQBO.FindAll<Item>(item, 1, 1).ToList<Item>(); QueryService <Invoice> inService = new QueryService <Invoice>(serviceContext); var In = inService.ExecuteIdsQuery("SELECT count(*) FROM Invoice").Count(); Batch batch = commonServiceQBO.CreateNewBatch(); batch.Add("select count(*) from Account", "queryAccount"); batch.Execute(); if (batch.IntuitBatchItemResponses != null && batch.IntuitBatchItemResponses.Count() > 0) { IntuitBatchResponse res = batch.IntuitBatchItemResponses.FirstOrDefault(); List <Account> acc = res.Entities.ToList().ConvertAll(item => item as Account); } ; Output("QBO call successful."); lblQBOCall.Visible = true; lblQBOCall.Text = "QBO Call successful"; } } catch (IdsException ex) { if (ex.Message == "Unauthorized-401") { Output("Invalid/Expired Access Token."); var tokenResp = await oauthClient.RefreshTokenAsync(dictionary["refreshToken"]); if (tokenResp.AccessToken != null && tokenResp.RefreshToken != null) { dictionary["accessToken"] = tokenResp.AccessToken; dictionary["refreshToken"] = tokenResp.RefreshToken; await QboApiCall(); } else { Output("Error while refreshing tokens: " + tokenResp.Raw); } } else { Output(ex.Message); } } catch (Exception ex) { Output("Invalid/Expired Access Token."); } }
/// <summary> /// Test QBO api call /// </summary> public async System.Threading.Tasks.Task QboApiCall() { try { if ((dictionary.ContainsKey("accessToken")) && (dictionary.ContainsKey("realmId"))) { Output("Making QBO API Call."); OAuth2RequestValidator oauthValidator = new OAuth2RequestValidator(dictionary["accessToken"]); ServiceContext serviceContext = new ServiceContext(dictionary["realmId"], IntuitServicesType.QBO, oauthValidator); serviceContext.IppConfiguration.BaseUrl.Qbo = "https://sandbox-quickbooks.api.intuit.com/"; //serviceContext.IppConfiguration.BaseUrl.Qbo = "https://quickbooks.api.intuit.com/";//prod serviceContext.IppConfiguration.MinorVersion.Qbo = "29"; ReportService reportService = new ReportService(serviceContext); //List<String> columndata = new List<String>(); //columndata.Add("tx_date"); //columndata.Add("dept_name"); //string coldata = String.Join(",", columndata); //reportService.columns = coldata; DataService commonServiceQBO = new DataService(serviceContext); Batch batch = commonServiceQBO.CreateNewBatch(); batch.Add("select * from Account", "queryAccount"); batch.Execute(); if (batch.IntuitBatchItemResponses != null && batch.IntuitBatchItemResponses.Count() > 0) { IntuitBatchResponse res = batch.IntuitBatchItemResponses.FirstOrDefault(); List <Account> acc = res.Entities.ToList().ConvertAll(item => item as Account); } ; QueryService <Purchase> inBalance = new QueryService <Purchase>(serviceContext); var bsheet = inBalance.ExecuteIdsQuery("SELECT * FROM Purchase WHERE MetaData.CreateTime >= '2001-10-14T04:05:05-07:00' Order by TxnDate DESC", QueryOperationType.query); decimal tot = decimal.Zero; foreach (var b in bsheet) { foreach (var l in b.Line) { tot += l.Amount; } } //((Intuit.Ipp.Data.AccountBasedExpenseLineDetail)l.AnyIntuitObject).AccountRef.name this.txtlog.Text = "Total Expenses: " + tot.ToString("c"); // var expenses = bsheet.Where(x => x.Classification == AccountClassificationEnum.Expense).ToList(); int a = 1; /* * DataService commonServiceQBO = new DataService(serviceContext); * QueryService<Invoice> inService = new QueryService<Invoice>(serviceContext); * var In = inService.ExecuteIdsQuery("SELECT count(*) FROM Invoice").Count(); * * Batch batch = commonServiceQBO.CreateNewBatch(); * * * batch.Add("select count(*) from Account", "queryAccount"); * batch.Execute(); * * if (batch.IntuitBatchItemResponses != null && batch.IntuitBatchItemResponses.Count() > 0) * { * IntuitBatchResponse res = batch.IntuitBatchItemResponses.FirstOrDefault(); * List<Account> acc = res.Entities.ToList().ConvertAll(item => item as Account); * }; * * Invoice invoice = QBOHelper.CreateInvoice(serviceContext); * //Adding the Invoice * Invoice added = Helper.Add<Invoice>(serviceContext, invoice); * */ Output("QBO call successful."); lblQBOCall.Visible = true; lblQBOCall.Text = "QBO Call successful"; } } catch (IdsException ex) { if (ex.Message == "Unauthorized-401") { Output("Invalid/Expired Access Token."); var tokenResp = await oauthClient.RefreshTokenAsync(dictionary["refreshToken"]); if (tokenResp.AccessToken != null && tokenResp.RefreshToken != null) { dictionary["accessToken"] = tokenResp.AccessToken; dictionary["refreshToken"] = tokenResp.RefreshToken; await QboApiCall(); } else { Output("Error while refreshing tokens: " + tokenResp.Raw); } } else { Output(ex.Message); } } catch (Exception ex) { Output("Invalid/Expired Access Token."); } }
public void batchtestall() { string accesstokenqbo = ConfigurationManager.AppSettings["accesstokenqbo"]; string accesstokensecretqbo = ConfigurationManager.AppSettings["accesstokensecretqbo"]; string consumerkeyqbo = ConfigurationManager.AppSettings["consumerkeyqbo"]; string consumersecretqbo = ConfigurationManager.AppSettings["consumersecretqbo"]; string realmiaqbo = ConfigurationManager.AppSettings["realmiaqbo"]; OAuthRequestValidator oauthrequestvalidator = new OAuthRequestValidator(accesstokenqbo, accesstokensecretqbo, consumerkeyqbo, consumersecretqbo); ServiceContext context = new ServiceContext(realmiaqbo, IntuitServicesType.QBO, oauthrequestvalidator); DataService service = new DataService(context); Customer customer1 = new Customer(); string guid = Guid.NewGuid().ToString("n"); customer1.GivenName = guid.Substring(0, 25); string GivenNameCustomer1 = customer1.GivenName; customer1.Title = guid.Substring(0, 15); customer1.MiddleName = guid.Substring(0, 5); customer1.FamilyName = guid.Substring(0, 25); customer1.DisplayName = guid.Substring(0, 20); Customer customer2 = new Customer(); guid = Guid.NewGuid().ToString("n"); customer2.GivenName = guid.Substring(0, 25); string GivenNameCustomer2 = customer2.GivenName; customer2.Title = guid.Substring(0, 15); customer2.MiddleName = guid.Substring(0, 5); customer2.FamilyName = guid.Substring(0, 25); customer2.DisplayName = guid.Substring(0, 20); try { Batch batch = service.CreateNewBatch(); batch.Add(customer1, "addcustomer1", OperationEnum.create); batch.Add(customer2, "addcustomer2", OperationEnum.create); batch.Add("select * from Customer startPosition 0 maxResults 10", "queryCustomer"); batch.Execute(); IntuitBatchResponse inuititemresponse = batch.IntuitBatchItemResponses[0]; Assert.IsTrue(inuititemresponse.ResponseType == ResponseType.Entity); Customer resultcustomer1 = inuititemresponse.Entity as Customer; Assert.IsFalse(string.IsNullOrEmpty(resultcustomer1.Id)); Assert.IsTrue(resultcustomer1.GivenName == GivenNameCustomer1); inuititemresponse = batch.IntuitBatchItemResponses[1]; Assert.IsTrue(inuititemresponse.ResponseType == ResponseType.Entity); Customer resultcustomer2 = inuititemresponse.Entity as Customer; Assert.IsFalse(string.IsNullOrEmpty(resultcustomer2.Id)); Assert.IsTrue(resultcustomer2.GivenName == GivenNameCustomer2); inuititemresponse = batch.IntuitBatchItemResponses[2]; Assert.IsTrue(inuititemresponse.ResponseType == ResponseType.Query); List <Customer> customers = inuititemresponse.Entities.ToList().ConvertAll(item => item as Customer); Assert.IsTrue(customers.Count >= 2); } catch (Ipp.Exception.IdsException ex) { Assert.Fail(ex.ToString()); } }
public void BatchTestAsync() { string accessTokenQBO = ConfigurationManager.AppSettings["AccessTokenQBO"]; string accessTokenSecretQBO = ConfigurationManager.AppSettings["AccessTokenSecretQBO"]; string consumerKeyQBO = ConfigurationManager.AppSettings["ConsumerKeyQBO"]; string ConsumerSecretQBO = ConfigurationManager.AppSettings["ConsumerSecretQBO"]; string realmIAQBO = ConfigurationManager.AppSettings["RealmIAQBO"]; OAuthRequestValidator oAuthRequestValidator = new OAuthRequestValidator(accessTokenQBO, accessTokenSecretQBO, consumerKeyQBO, ConsumerSecretQBO); ServiceContext context = new ServiceContext(realmIAQBO, IntuitServicesType.QBO, oAuthRequestValidator); DataService service = new DataService(context); Customer customer = new Customer(); string guid = Guid.NewGuid().ToString("N"); customer.GivenName = guid.Substring(0, 25); customer.Title = guid.Substring(0, 15); customer.MiddleName = guid.Substring(0, 5); customer.FamilyName = guid.Substring(0, 25); customer.DisplayName = guid.Substring(0, 20); try { ManualResetEvent manualEvent = new ManualResetEvent(false); Batch batch = service.CreateNewBatch(); batch.Add(customer, "addCustomer", OperationEnum.create); batch.Add("select * from Customer startPosition 0 maxResults 10", "queryCustomer"); batch.OnBatchExecuteAsyncCompleted += (sender, e) => { Assert.IsNotNull(e); if (e.Batch != null) { IntuitBatchResponse addCustomerResponse = e.Batch.IntuitBatchItemResponses[0]; if (addCustomerResponse.ResponseType != ResponseType.Exception) { Customer addedcustomer = addCustomerResponse.Entity as Customer; Assert.IsNotNull(customer); Assert.IsFalse(string.IsNullOrEmpty(addedcustomer.Id)); } else { Assert.Fail(); } IntuitBatchResponse queryCustomerResponse = e.Batch.IntuitBatchItemResponses[1]; if (queryCustomerResponse.ResponseType != ResponseType.Exception) { List <Customer> customers = queryCustomerResponse.Entities.ToList().ConvertAll(item => item as Customer); Assert.IsNotNull(customers); Assert.IsTrue(customers.Count > 1); } else { Assert.Fail(); } } else { Assert.Fail(); } manualEvent.Set(); }; batch.ExecuteAsync(); manualEvent.WaitOne(30000); } catch (Ipp.Exception.IdsException ex) { Assert.Fail(ex.ToString()); } }