Global API
...
Request
Purchase Order
Create
1min
Here is the below example on how to to create a PO using Breadwinners Global API.
Request
Response
1// Create a Map to store all the data of a Purchase Order
2List<Object> purchaseOrderList = new List<Object>();
3Map<String, Object> purchaseOrderMap = new Map<String, Object>();
4 purchaseOrderMap.put('DateString', '2021-11-11T00:00:00');
5 purchaseOrderMap.put('DeliveryDate', '2021-12-06T00:00:00');
6 purchaseOrderMap.put('Status', 'DRAFT');
7
8 // Initializing the Contact
9 Map<String, Object> contactMap = new Map<String, Object>();
10 contactMap.put('ContactID', 'c84ebb15-0a8d-4145-933f-203e68d014a0');
11 purchaseOrderMap.put('Contact', contactMap);
12 // Initializing the Purchase Order Line Items
13 List<Object> lineItemList = new List<Object>();
14 Map<String, Object> lineItemMap = new Map<String, Object>();
15 lineItemMap.put('Description', 'Line Item Description');
16 lineItemMap.put('UnitAmount', 100);
17 lineItemMap.put('Quantity', 10);
18 lineItemMap.put('AccountCode', '310');
19 lineItemList.add(lineItemMap);
20
21 // Adding the Line Items to Purchase Order
22 purchaseOrderMap.put('LineItems', lineItemList);
23 purchaseOrderList.add(purchaseOrderMap);
24
25// Initializing the RequestJSON Data to be passed.
26 Map<String, Object> reqJSONMap = new Map<String, Object>();
27 reqJSONMap.put('purchaseOrders', purchaseOrderList);
28 String reqJSON = JSON.serialize(reqJSONMap);
29
30 Map<String, Object> finalReqMap = new Map<String, Object>();
31 Map<String, Object> reqOptions = new Map<String, Object>();
32 finalReqMap.put('queryParameters', reqOptions);
33 finalReqMap.put('version', '1.0');
34 finalReqMap.put('action', 'createPurchaseOrder');
35 finalReqMap.put('RequestJSON', reqJSON);
36 finalReqMap.put('skipDML', false);
37 //Required, if Xero Multi-Org is enabled in Breadwinner.
38 finalReqMap.put('xeroOrgId', '!aa00TM');
39 System.debug('Request ::: ' + finalReqMap);
40
41// Placing a request to Breadwinner Global API
42 Map<String, Object> respMap = bread_winner.BreadwinnerXeroAPI.call(finalReqMap);
43 System.debug('Response ::: ' + respMap);