In this article, we will learn how to add 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.
CustomerRef and Line elements are required for creating an estimate, we will use these two required elements for creating an estimate.
We have to give the customer reference in CustomerRef, and items or item reference with other details (like quantity) in Line.
Item must be already added in Quickbooks before adding it to the estimate.
Also If we do not provide the shipping address and billing address, then the address from the referenced Customer object is used.
Let’s create an Estimate.
public ActionResult CreateEstimate() { 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; Estimate ObjEstimate = new Estimate(); ObjEstimate.CustomerRef = new ReferenceType(); ObjEstimate.CustomerRef.Value = "58"; //Quickbooks online Customer Id List<Line> LineList = new List<Line>(); Line objLine = new Line(); objLine.DetailTypeSpecified = true; objLine.DetailType = LineDetailTypeEnum.SalesItemLineDetail; objLine.AmountSpecified = true; objLine.Amount = 100; SalesItemLineDetail salesItemLineDetail = new SalesItemLineDetail(); salesItemLineDetail.QtySpecified = true; salesItemLineDetail.Qty = 1; salesItemLineDetail.ItemRef = new ReferenceType(); salesItemLineDetail.ItemRef.Value = "19"; //Quickbooks online Item Id objLine.AnyIntuitObject = salesItemLineDetail; LineList.Add(objLine); ObjEstimate.Line = LineList.ToArray(); DataService dataService = new DataService(serviceContext); Estimate EstimateAdd = dataService.Add(ObjEstimate); if (EstimateAdd != null && !string.IsNullOrEmpty(EstimateAdd.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 = "CreateEstimate"; } <h2>Create Estimate</h2> @if (ViewBag.IsSuccess != null && ViewBag.IsSuccess == true) { <div class="row"> <label class="label label-success"> Estimate Created Successfully </label> </div> } else if (ViewBag.IsSuccess != null && ViewBag.IsSuccess == false) { <div class="row"> <label class="label label-danger">@ViewBag.Message</label> </div> }
OUTPUT:(estimate preview on Quickbook online)
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
View Comments
How to link estimate and invoice using c#?