In this article, we will learn how to update an invoice 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.
public ActionResult UpdateInvoice() { 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 Invoice where id = '{0}'", "147"); var queryService = new QueryService<Invoice>(serviceContext); Invoice objInvoiceFound = queryService.ExecuteIdsQuery(EXISTING_INVOICE_QUERYBYID).FirstOrDefault<Invoice>(); //If Invoice found on Quickbooks online if (objInvoiceFound != null) { Invoice ObjInvoice = new Invoice(); ObjInvoice.Id= objInvoiceFound.Id; ObjInvoice.SyncToken= objInvoiceFound.SyncToken; ObjInvoice.CustomerRef = new ReferenceType(); ObjInvoice.CustomerRef = objInvoiceFound.CustomerRef; List<Line> LineList = new List<Line>(); for (int i = 0; i < objInvoiceFound.Line.Count(); i++) { if (objInvoiceFound.Line[i].DetailType == LineDetailTypeEnum.SalesItemLineDetail) { objInvoiceFound.Line[i].Amount = 150; objInvoiceFound.Line[i].Description = "This Description is for invoice"; LineList.Add(objInvoiceFound.Line[i]); } } ObjInvoice.Line = LineList.ToArray(); DataService dataService = new DataService(serviceContext); Invoice UpdateEntity = dataService.Update<Invoice>(ObjInvoice); 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 = "UpdateInvoice"; } <h2>UpdateInvoice</h2> @if (ViewBag.IsSuccess != null && ViewBag.IsSuccess == true) { <div class="row"> <label class="label label-success"> Invoice Updated Successfully </label> </div> } else if (ViewBag.IsSuccess != null && ViewBag.IsSuccess == false) { <div class="row"> <label class="label label-danger">@ViewBag.Message</label> </div> }
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