In this article, we will learn how to update an estimate in Quickbooks online from .NET MVC web application using SDK.
Before using any Quickbooks online API we need access token, if you don’t know how to get access token then you can find it here.
Following are a few steps for updating estimate,
public ActionResult UpdateEstimate() { try { OAuth2RequestValidator oauthValidator = new OAuth2RequestValidator(Access_token); // Create a ServiceContext with Auth tokens and realmId ServiceContext serviceContext = new ServiceContext(RealmId, IntuitServicesType.QBO, oauthValidator); serviceContext.IppConfiguration.MinorVersion.Qbo = "23"; serviceContext.IppConfiguration.BaseUrl.Qbo = QboBaseUrl; string EXISTING_INVOICE_QUERYBYID = string.Format("select * from Estimate where id = '{0}'", "149"); var queryService = new QueryService<Estimate>(serviceContext); Estimate objEstimateFound = queryService.ExecuteIdsQuery(EXISTING_INVOICE_QUERYBYID).FirstOrDefault<Estimate>(); //If Invoice found on Quickbooks online if (objEstimateFound != null) { Estimate ObjEstimate = new Estimate(); ObjEstimate.Id = objEstimateFound.Id; ObjEstimate.SyncToken = objEstimateFound.SyncToken; ObjEstimate.CustomerRef = new ReferenceType(); ObjEstimate.CustomerRef = objEstimateFound.CustomerRef; List<Line> LineList = new List<Line>(); for (int i = 0; i < objEstimateFound.Line.Count(); i++) { if (objEstimateFound.Line[i].DetailType == LineDetailTypeEnum.SalesItemLineDetail) { objEstimateFound.Line[i].Amount = 150; objEstimateFound.Line[i].Description = "This Keyboard and mouse is sold by vision infotech"; LineList.Add(objEstimateFound.Line[i]); } } ObjEstimate.Line = LineList.ToArray(); DataService dataService = new DataService(serviceContext); Estimate UpdateEntity = dataService.Update<Estimate>(ObjEstimate); if (UpdateEntity != null && !string.IsNullOrEmpty(UpdateEntity.Id)) { //you can write Database code here ViewBag.IsSuccess = true; } } return View(); } catch (IdsException ex) { ViewBag.IsSuccess = false; if (ex.InnerException != null && !string.IsNullOrEmpty(ex.InnerException.Message)) { ViewBag.Message = ex.InnerException.Message; } else if (!string.IsNullOrEmpty(ex.Message)) { ViewBag.Message = ex.Message; } else { ViewBag.Message = "Something went wrong,IdsException occurs"; } return View(); } catch (Exception ex) { ViewBag.IsSuccess = false; if (ex.InnerException != null && !string.IsNullOrEmpty(ex.InnerException.Message)) { ViewBag.Message = ex.InnerException.Message; } else if (!string.IsNullOrEmpty(ex.Message)) { ViewBag.Message = ex.Message; } else { ViewBag.Message = "Something went wrong,Exception occurs"; } return View(); } }
@{ ViewBag.Title = "UpdateEstimate"; } <h2>Update Estimate</h2> @if (ViewBag.IsSuccess != null && ViewBag.IsSuccess == true) { <div class="row"> <label class="label label-success"> Estimate Updated Successfully </label> </div> } else if (ViewBag.IsSuccess != null && ViewBag.IsSuccess == false) { <div class="row"> <label class="label label-danger">@ViewBag.Message</label> </div> }
The above code will update the estimate item’s amount and description, here we are changing the amount of estimate object that we got from Quickbooks online and assigning it to our newly created object for an update.
In this article, we have to show Create and Used PIPE in angular
In this article, we have to show Create and Used PIPE in angular
In this article, we have to show Create and Used PIPE in angular