Global API
Code Examples
Create and Send Invoice
1min
The Global API allows you to send an invoice after it has been created in Quickbooks. To do this, you need to add two additional parameters. Set "SendInvoice" to true and include the recipient's email address in the "BillEmail" field.
Request
Response
1// Create a Map to store all the data of a Invoice
2Map<String, Object> invoiceMap = new Map<String, Object>();
3invoiceMap.put('TxnDate', '2021/08/11');
4invoiceMap.put('DueDate', '2021/09/11');
5invoiceMap.put('DocNumber', 'Inv-1201');
6invoiceMap.put('ExchangeRate', 1.0);
7
8/*
9 * Add this to send the invoice after creation
10 */
11invoiceMap.put('SendInvoice', true);
12
13
14invoiceMap.put('Address',new Map<String, Object>{'FreeFormNumber' => '+919090909090'});
15invoiceMap.put('SalesTermRef',new Map<String, Object>{'value' => '4'});
16invoiceMap.put('CustomerRef',new Map<String, Object>{'value' => '29'});
17
18// Initialize the Billing Address
19Map<String, Object> billAddrMap = new Map<String, Object>();
20billAddrMap.put('City' , 'Suryapet');
21billAddrMap.put('Country' , 'India');
22billAddrMap.put('Line3' , 'Kodad');
23billAddrMap.put('Line2' , 'First Lane');
24billAddrMap.put('Line1' , '1-24');
25billAddrMap.put('PostalCode' , '508238');
26billAddrMap.put('CountrySubDivisionCode' , '');
27invoiceMap.put('BillAddr',billAddrMap);
28
29// Initialize the Email Address
30/*
31 * This is required if you want to send the invoice after creation
32*/
33Map<String, object> billEmail = new Map<String, object>();
34billEmail.put('Address','[email protected]');
35invoiceMap.put('BillEmail',billEmail);
36
37// Initialize the Invoice Line Items
38List<Object> lineItemList = new List<Object>();
39Map<String, Object> lineItemMap = new Map<String, Object>();
40lineItemMap.put('LineNum',1);
41lineItemMap.put('Amount',100);
42lineItemMap.put('Description','Description');
43lineItemMap.put('DetailType', 'SalesItemLineDetail');
44
45Map<String, Object> salesLineItemDetailMap = new Map<String, Object>();
46salesLineItemDetailMap.put('ItemRef' , new Map<String, Object>{'value' => '1'});
47salesLineItemDetailMap.put('TaxCodeRef' , new Map<String, Object>{'value' => 'TAX'});
48salesLineItemDetailMap.put('ClassRef' , new Map<String, Object>{'value' => '5000000000000193289'});
49salesLineItemDetailMap.put('ServiceDate','1993/05/25'); //yyyy/MM/dd
50salesLineItemDetailMap.put('Qty',2);
51salesLineItemDetailMap.put('UnitPrice',50);
52salesLineItemDetailMap.put('TaxInclusiveAmt',22);
53
54lineItemMap.put('SalesItemLineDetail', salesLineItemDetailMap);
55lineItemList.add(lineItemMap);
56
57List<Object> invoiceList = new List<Object>();
58
59// Add the Line Items to Invoice
60invoiceMap.put('Line',lineItemList);
61invoiceList.add(invoiceMap);
62
63// Initializing the RequestJSON Data to be passed.
64Map<String, Object> reqJSONMap = new Map<String, Object>();
65reqJSONMap.put('invoices' , invoiceList);
66String reqJSON = JSON.serialize(reqJSONMap);
67
68Map<String, Object> finalReqMap = new Map<String, Object>();
69finalReqMap.put('version' , '1.0');
70finalReqMap.put('action' , 'createinvoice');
71finalReqMap.put('RequestJSON' , reqJSON);
72finalReqMap.put('skipDML' , false);
73//Required, if QuickBooks Multi-Org is enabled in Breadwinner.
74finalReqMap.put('qbOrgId', '4620816365285051610');
75System.debug('Request ::: ' + finalReqMap);
76
77// Place the request to Breadwinner Global API
78Map<String, Object> respMap = breadwinner_qbo.BreadwinnerQBAPI.call(finalReqMap);
79System.debug('Response ::: ' + respMap);
Do you want to know the list of supported parameters for Create and Send Invoice? See here.
Updated 06 Jun 2024
Did this page help you?