In this article, we will learn how to add a purchase order 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.
VendorRef, Line and APAccountRef elements are required for creating a purchase order, we will use these required elements for creating a purchase order.
We have to give the vendor reference in VendorRef, items or item reference in Line, and account reference in APAccountRef.
Vendor, Items, and Account must be already added in Quickbooks before adding it to the purchase order.
Let’s create a Purchase Order.
public ActionResult CreatePurchaseOrder() { 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; PurchaseOrder ObjPurchaseOrder = new PurchaseOrder(); ObjPurchaseOrder.APAccountRef = new ReferenceType(); ObjPurchaseOrder.APAccountRef.Value = "33"; //Quickbooks online Accounts Id of type Accounts Payable // We can give Accounts Name insted of Accounts Id, if we give Accounts Id and Accounts Name both then Accounts name will be ignore. //ObjPurchaseOrder.APAccountRef.name = "Accounts Payable (A/P)";//Quickbooks online Accounts Name ObjPurchaseOrder.VendorRef = new ReferenceType(); ObjPurchaseOrder.VendorRef.Value = "60";//Quickbooks online Vendor Id // We can give Vendor Name insted of Vendor Id, if we give Vendor Id and Vendor Name both then Vendor name will be ignore. //ObjPurchaseOrder.VendorRef.name = "Tabish Vendor";//Quickbooks online Vendor Name List<Line> LineList = new List<Line>(); Line objLine = new Line(); objLine.DetailTypeSpecified = true; objLine.DetailType = LineDetailTypeEnum.ItemBasedExpenseLineDetail; objLine.AmountSpecified = true; objLine.Amount = 100; ItemBasedExpenseLineDetail itemLineDetail = new ItemBasedExpenseLineDetail(); itemLineDetail.ItemRef = new ReferenceType(); itemLineDetail.ItemRef.Value = "19"; //Quickbooks online Item Id // We can give Item Name insted of Item Id, if we give Item Id and Item Name both then Item name will be ignore. //itemLineDetail.ItemRef.name = "Vision Keyboard Mouse Set"; //Quickbooks online Item name itemLineDetail.CustomerRef = new ReferenceType(); itemLineDetail.CustomerRef.Value = "58"; //Quickbooks online Customer Id // We can give Customer Name insted of Customer Id, if we give Customer Id and Customer Name both then Customer name will be ignore. //itemLineDetail.CustomerRef.name = "Tabish Rangrej"; //Quickbooks online Customer Name itemLineDetail.QtySpecified = true; itemLineDetail.Qty = 1; objLine.AnyIntuitObject = itemLineDetail; LineList.Add(objLine); ObjPurchaseOrder.Line = LineList.ToArray(); DataService dataService = new DataService(serviceContext); PurchaseOrder PurchaseOrderAdd = dataService.Add(ObjPurchaseOrder); if (PurchaseOrderAdd != null && !string.IsNullOrEmpty(PurchaseOrderAdd.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 = "CreatePurchaseOrder"; } <h2>Create Purchase Order</h2> @if (ViewBag.IsSuccess != null && ViewBag.IsSuccess == true) { <div class="row"> <label class="label label-success"> Purchase Order 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:(Purchase Order 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