Global API
...
Request
Purchase Order
Create
1min
The following is an example of creating a Purchase Order where we are setting every possible field (See Purchase Order for the available fields). The response will return the exact request data plus the new QuickBooks PurchaseOrder ID (Id).
Note: You can only create one record at a time.
Request
Response
1// Create a Map to store all the data of a Purchase Order
2 Map<String, Object> purchaseOrderMap = new Map<String, Object>();
3 List<Object> lineItemList = new List<Object>();
4 List<Object> purchaseOrderList = new List<Object>();
5
6// Assign value of Opportunity to QuickBook PurchaseOrder
7 purchaseOrderMap.put('TxnDate','2024-04-26');
8 purchaseOrderMap.put('DueDate','2024-05-26');
9 purchaseOrderMap.put('DocNumber', '0001');
10 purchaseOrderMap.put('VendorRef' , new Map<String, Object>{'value' => '67' });
11 purchaseOrderMap.put('PrivateNote' , 'create');
12 Map<String, Object> lineItemMap = new Map<String, Object>();
13 Map<String, Object> salesLineItemDetailMap = new Map<String, Object>();
14 lineItemMap.put('DetailType','ItemBasedExpenseLineDetail');
15 lineItemMap.put('Amount',1000);
16 salesLineItemDetailMap.put('ItemRef' , new Map<String, Object>{'value' => '19' });
17 salesLineItemDetailMap.put('Qty','10');
18 salesLineItemDetailMap.put('UnitPrice','100');
19 if(lineItemMap.get('DetailType') == 'SalesItemLineDetail'){
20 lineItemMap.put('SalesItemLineDetail',salesLineItemDetailMap);
21 }else if(lineItemMap.get('DetailType') == 'ItemBasedExpenseLineDetail'){
22 lineItemMap.put('ItemBasedExpenseLineDetail',salesLineItemDetailMap);
23 }
24 lineItemList.add(lineItemMap);
25
26// Adding the Line Items to QuickBook PurchaseOrder
27 purchaseOrderMap.put('Line',lineItemList);
28 purchaseOrderList.add(purchaseOrderMap);
29 Map<String, Object> reqJSONMap = new Map<String, Object>();
30 reqJSONMap.put('PurchaseOrder' , purchaseOrderList);
31 String reqJSON = JSON.serialize(reqJSONMap);
32 Map<String, Object> finalReqMap = new Map<String, Object>();
33 Map<String,Object> reqOptions = new Map<String,Object>();
34 finalReqMap.put('options' , reqOptions);
35 finalReqMap.put('version' , '1.0');
36 finalReqMap.put('action' , 'createPurchaseOrder');
37 finalReqMap.put('RequestJSON' , reqJSON);
38 // Required, if QuickBooks Multi-Org is enabled in Breadwinner.
39 finalReqMap.put('qbOrgId' , '4620816365285051610');
40 finalReqMap.put('skipDML' , false);
41 System.debug('Request ::: ' + finalReqMap);
42 Map<String, Object> respMap = breadwinner_qbo.BreadwinnerQBAPI.call(finalReqMap);
43 System.debug('Response ::: ' + respMap);