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
// Create a Map to store all the data of a Invoice
Map<String, Object> invoiceMap = new Map<String, Object>();
invoiceMap.put('TxnDate', '2021/08/11');
invoiceMap.put('DueDate', '2021/09/11');
invoiceMap.put('DocNumber', 'Inv-1201');
invoiceMap.put('ExchangeRate', 1.0);
/*
* Add this to send the invoice after creation
*/
invoiceMap.put('SendInvoice', true);
invoiceMap.put('Address',new Map<String, Object>{'FreeFormNumber' => '+919090909090'});
invoiceMap.put('SalesTermRef',new Map<String, Object>{'value' => '4'});
invoiceMap.put('CustomerRef',new Map<String, Object>{'value' => '29'});
// Initialize the Billing Address
Map<String, Object> billAddrMap = new Map<String, Object>();
billAddrMap.put('City' , 'Suryapet');
billAddrMap.put('Country' , 'India');
billAddrMap.put('Line3' , 'Kodad');
billAddrMap.put('Line2' , 'First Lane');
billAddrMap.put('Line1' , '1-24');
billAddrMap.put('PostalCode' , '508238');
billAddrMap.put('CountrySubDivisionCode' , '');
invoiceMap.put('BillAddr',billAddrMap);
// Initialize the Email Address
/*
* This is required if you want to send the invoice after creation
*/
Map<String, object> billEmail = new Map<String, object>();
billEmail.put('Address','[email protected]');
invoiceMap.put('BillEmail',billEmail);
// Initialize the Invoice Line Items
List<Object> lineItemList = new List<Object>();
Map<String, Object> lineItemMap = new Map<String, Object>();
lineItemMap.put('LineNum',1);
lineItemMap.put('Amount',100);
lineItemMap.put('Description','Description');
lineItemMap.put('DetailType', 'SalesItemLineDetail');
Map<String, Object> salesLineItemDetailMap = new Map<String, Object>();
salesLineItemDetailMap.put('ItemRef' , new Map<String, Object>{'value' => '1'});
salesLineItemDetailMap.put('TaxCodeRef' , new Map<String, Object>{'value' => 'TAX'});
salesLineItemDetailMap.put('ClassRef' , new Map<String, Object>{'value' => '5000000000000193289'});
salesLineItemDetailMap.put('ServiceDate','1993/05/25'); //yyyy/MM/dd
salesLineItemDetailMap.put('Qty',2);
salesLineItemDetailMap.put('UnitPrice',50);
salesLineItemDetailMap.put('TaxInclusiveAmt',22);
lineItemMap.put('SalesItemLineDetail', salesLineItemDetailMap);
lineItemList.add(lineItemMap);
List<Object> invoiceList = new List<Object>();
// Add the Line Items to Invoice
invoiceMap.put('Line',lineItemList);
invoiceList.add(invoiceMap);
// Initializing the RequestJSON Data to be passed.
Map<String, Object> reqJSONMap = new Map<String, Object>();
reqJSONMap.put('invoices' , invoiceList);
String reqJSON = JSON.serialize(reqJSONMap);
Map<String, Object> finalReqMap = new Map<String, Object>();
finalReqMap.put('version' , '1.0');
finalReqMap.put('action' , 'createinvoice');
finalReqMap.put('RequestJSON' , reqJSON);
finalReqMap.put('skipDML' , false);
//Required, if QuickBooks Multi-Org is enabled in Breadwinner.
finalReqMap.put('qbOrgId', '!aa00TM');
System.debug('Request ::: ' + finalReqMap);
// Place the request to Breadwinner Global API
Map<String, Object> respMap = breadwinner_qbo.BreadwinnerQBAPI.call(finalReqMap);
System.debug('Response ::: ' + respMap);
Do you want to know the list of supported parameters for Create and Send Invoice? See here.
Updated 17 Jan 2024
Did this page help you?