Create
1 min
In this example, we are creating a Credit Note for an Invoice, but the same process can also be used for Bills with minor adjustments, as noted in the comments within the request.
To create a Credit Note, set the field "Type" with the value "ACCRECCREDIT" for Sales Credit Note and "ACCPAYCREDIT" for Bill Credit Note, respectively.
// Create a List to store credit notes data
List<Object> creditNoteList = new List<Object>();
Map<String, Object> creditNoteMap = new Map<String, Object>();
// REQUIRED: Credit Note type
// Use 'ACCRECCREDIT' for Sales Credit Note
// Use 'ACCPAYCREDIT' for Bill Credit Note
creditNoteMap.put('Type', 'ACCRECCREDIT');
// Set the Credit Note Date
creditNoteMap.put('Date', '2021-11-11');
// Line amount type (Exclusive / Inclusive / NoTax)
creditNoteMap.put('LineAmountTypes', 'Exclusive');
// Status of the Credit Note
creditNoteMap.put('Status', 'DRAFT');
//Contact Information
Map<String, Object> contactMap = new Map<String, Object>();
contactMap.put('ContactID', 'c84ebb15-0a8d-4145-933f-203e68d014a0');
creditNoteMap.put('Contact', contactMap);
// Credit Note Line Items
List<Object> lineItemList = new List<Object>();
Map<String, Object> lineItemMap = new Map<String, Object>();
lineItemMap.put('Description', 'Line Item Description');
lineItemMap.put('Quantity', 10);
lineItemMap.put('UnitAmount', 100);
lineItemMap.put('AccountCode', '200');
lineItemList.add(lineItemMap);
// Attach line items to Credit Note
creditNoteMap.put('LineItems', lineItemList);
// Add Credit Note to list
creditNoteList.add(creditNoteMap);
// Request JSON Payload
Map<String, Object> reqJSONMap = new Map<String, Object>();
reqJSONMap.put('creditnotes', creditNoteList);
String reqJSON = JSON.serialize(reqJSONMap);
// Final Global API Request
Map<String, Object> finalReqMap = new Map<String, Object>();
Map<String, Object> reqOptions = new Map<String, Object>();
finalReqMap.put('queryParameters', reqOptions);
finalReqMap.put('version', '1.0');
finalReqMap.put('action', 'createCreditNote');
finalReqMap.put('RequestJSON', reqJSON);
finalReqMap.put('skipDML', false);
// REQUIRED if Xero Multi-Org is enabled
finalReqMap.put('xeroOrgId', '!aa00TM'); // Replace with your Xero Org ID
System.debug('CN Create Request ::: ' + finalReqMap);
// Call Breadwinner Global API
Map<String, Object> respMap = bread_winner.BreadwinnerXeroAPI.call(finalReqMap);
System.debug('CN Create Response ::: ' + respMap);