Global API
...
Request
Invoice
Create
1min
The following is an example of creating an Invoice where we are setting every possible field (See Invoice for the available fields). The response will return the exact request data, the new QuickBooks Invoice ID (Id), and the newly created Salesforce Invoice ID (salesforceRecordId). @Code this example if you also want to send the invoice during creation.
Note: You can only create one record at a time.
Request
Response
1// Create a Map to store all the data of a Invoice
2List<Object> invoiceList = new List<Object>();
3Map<String, Object> invoiceMap = new Map<String, Object>();
4 invoiceMap.put('TxnDate', '2021/08/11');
5 invoiceMap.put('DueDate', '2021/09/11');
6 invoiceMap.put('DocNumber', 'Inv-1201');
7 invoiceMap.put('ExchangeRate', 1.0);
8
9 // Initializing the Invoice Custom Fields
10 List<Object> customFieldList = new List<Object>();
11 Map<String, Object> customFiel1dMap = new Map<String, Object>();
12 customFiel1dMap.put('DefinitionId','1');
13 customFiel1dMap.put('Type','StringType');
14 customFiel1dMap.put('StringValue','Received');
15 customFieldList.add(customFiel1dMap);
16
17 // Adding the Invoice Custom Fields
18 invoiceMap.put('CustomField',customFieldList);
19
20 invoiceMap.put('Address',new Map<String, Object>{'FreeFormNumber' => '+919090909090'});
21 invoiceMap.put('SalesTermRef',new Map<String, Object>{'value' => '4'});
22 invoiceMap.put('CustomerRef',new Map<String, Object>{'value' => '29'});
23
24 // Initializing the Billing Address
25 Map<String, Object> billAddrMap = new Map<String, Object>();
26 billAddrMap.put('City' , 'Suryapet');
27 billAddrMap.put('Country' , 'India');
28 billAddrMap.put('Line3' , 'Kodad');
29 billAddrMap.put('Line2' , 'First Lane');
30 billAddrMap.put('Line1' , '1-24');
31 billAddrMap.put('PostalCode' , '508238');
32 billAddrMap.put('CountrySubDivisionCode' , '');
33 invoiceMap.put('BillAddr',billAddrMap);
34
35 // Initializing the Invoice Line Items
36 List<Object> lineItemList = new List<Object>();
37 Map<String, Object> lineItemMap = new Map<String, Object>();
38 lineItemMap.put('LineNum',1);
39 lineItemMap.put('Amount',100);
40 lineItemMap.put('Description','Description');
41 lineItemMap.put('DetailType', 'SalesItemLineDetail');
42
43 Map<String, Object> salesLineItemDetailMap = new Map<String, Object>();
44 salesLineItemDetailMap.put('ItemRef' , new Map<String, Object>{'value' => '1'});
45 salesLineItemDetailMap.put('TaxCodeRef' , new Map<String, Object>{'value' => 'TAX'});
46 salesLineItemDetailMap.put('ClassRef' , new Map<String, Object>{'value' => '5000000000000193289'});
47 salesLineItemDetailMap.put('ServiceDate','1993/05/25'); //yyyy/MM/dd
48 salesLineItemDetailMap.put('Qty',2);
49 salesLineItemDetailMap.put('UnitPrice',50);
50 salesLineItemDetailMap.put('TaxInclusiveAmt',22);
51
52 lineItemMap.put('SalesItemLineDetail', salesLineItemDetailMap);
53 lineItemList.add(lineItemMap);
54
55 // Shipping charge is applied as a part of line items
56 Map<String, Object> shippingLineItemMap = new Map<String, Object>();
57 shippingLineItemMap.put('Amount',10);
58 shippingLineItemMap.put('DetailType', 'SalesItemLineDetail');
59
60 Map<String, Object> shippingSalesLineItemDetailMap = new Map<String, Object>();
61 shippingSalesLineItemDetailMap.put('ItemRef' , new Map<String, Object>{'value' => 'SHIPPING_ITEM_ID'});
62 shippingSalesLineItemDetailMap.put('TaxCodeRef' , new Map<String, Object>{'value' => 'TAX'});
63
64 shippingLineItemMap.put('SalesItemLineDetail', shippingSalesLineItemDetailMap);
65 lineItemList.add(shippingLineItemMap);
66
67 // Adding the Line Items to Invoice
68 invoiceMap.put('Line',lineItemList);
69 invoiceList.add(invoiceMap);
70
71// Initializing the RequestJSON Data to be passed.
72 Map<String, Object> reqJSONMap = new Map<String, Object>();
73 reqJSONMap.put('invoices' , invoiceList);
74 String reqJSON = JSON.serialize(reqJSONMap);
75
76 Map<String, Object> finalReqMap = new Map<String, Object>();
77 Map<String, Object> reqOptions = new Map<String, Object>();
78 finalReqMap.put('options' , reqOptions);
79 finalReqMap.put('version' , '1.0');
80 finalReqMap.put('action' , 'createinvoice');
81 finalReqMap.put('RequestJSON' , reqJSON);
82 finalReqMap.put('skipDML' , false);
83 //Required, if QuickBooks Multi-Org is enabled in Breadwinner.
84 finalReqMap.put('qbOrgId', '4620816365285051610');
85 System.debug('Request ::: ' + finalReqMap);
86
87// Placing a request to Breadwinner Global API
88 Map<String, Object> respMap = breadwinner_qbo.BreadwinnerQBAPI.call(finalReqMap);
89 System.debug('Response ::: ' + respMap);