In this article, we will learn how to get purchase orders from Quickbooks online in .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 GetAllPurchaseOrder() { List<PurchaseOrder> PurchaseOrderList = new List<PurchaseOrder>(); 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; // Create a QuickBooks QueryService using ServiceContext QueryService<PurchaseOrder> querySvc = new QueryService<PurchaseOrder>(serviceContext); PurchaseOrderList = querySvc.ExecuteIdsQuery("SELECT * FROM PurchaseOrder").ToList(); return View(PurchaseOrderList); } catch (IdsException ex) { return View(PurchaseOrderList); } catch (Exception ex) { return View(PurchaseOrderList); } }
@model List<Intuit.Ipp.Data.PurchaseOrder> @using Intuit.Ipp.Data; @{ ViewBag.Title = "GetAllPurchaseOrder"; } <h2>Quickbooks online Purchase Order List</h2> <div> <table class="table table-bordered"> @foreach (var item in Model) { <tr style="border: 2px solid black;border-bottom: none;background-color:#a9a9a9"> <th>QBO Purchase Order ID</th> <th>Purchase Order Number</th> <th>Purchase Order Date</th> <th>Vendor</th> <th>Total Amount</th> </tr> <tr style="border: 2px solid black;border-bottom: none;border-top: none;"> <td>@item.Id</td> <td>@item.DocNumber</td> <td>@item.TxnDate.ToString("MM/dd/yyyy")</td> <td>@item.VendorRef.name</td> <td>@item.TotalAmt</td> </tr> <tr style="border: 2px solid black;border-top: none;"> @*<td>Items Details</td>*@ <td colspan="5"> <table class="table table-bordered"> <tr> <td colspan="5" style="text-align:center;"><label>Items Details</label></td> </tr> <tr> <th>Line Id</th> <th>Item Name</th> <th>Qty</th> <th>Total Amount</th> <th>Description</th> </tr> @foreach (var LineItem in item.Line) { <tr> <td>@LineItem.Id</td> @{ ItemBasedExpenseLineDetail Expenseitem = (ItemBasedExpenseLineDetail)LineItem.AnyIntuitObject; } <td>@Expenseitem.ItemRef.name</td> <td> @if (Expenseitem.QtySpecified) { @Expenseitem.Qty } </td> <td> @if (LineItem.AmountSpecified) { @LineItem.Amount } </td> <td>@LineItem.Description</td> </tr> } </table> </td> </tr> } </table> </div>
string EXISTING_PURCHASEORDER_QUERYBYID = string.Format("select * from PurchaseOrder where id = '{0}'", "155"); PurchaseOrder objPurchaseOrderFound = queryService.ExecuteIdsQuery(EXISTING_PURCHASEORDER_QUERYBYID).FirstOrDefault<PurchaseOrder>();
So that’s how we can get purchase orders or query purchase orders from Quickbooks online.
Output:
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