Apply
1 min
in this example, we are applying a credit note to an invoice, but the same process can also be used for bills with minor adjustments, as noted in the comments within the request to apply a credit note to an invoice in xero, you need to provide the unique ids of both the invoice and the credit note in the "invoiceid" and "creditnoteid" fields set creditnotetype to "invoice" when applying it to an invoice, or "bill" when applying it to a bill note when skipdml is set to false, the system performs dml operations and updates the credit note, payment, and invoice records in salesforce request // create a list to store allocation data list\<object> allocationlist = new list\<object>(); map\<string, object> allocationmap = new map\<string, object>(); // set the allocation amount (amount to apply from credit note to invoice) allocationmap put('amount', 10); // set the allocation date allocationmap put('date', '2026 02 01'); // initializing the invoice to apply the allocation to // this must be a valid existing record in xero map\<string, object> invoicemap = new map\<string, object>(); // note invoiceid can be either an invoice or bill id from xero invoicemap put('invoiceid', '72aac89b a824 45d1 aa4d 0b9c59440917'); // replace the id with your valid invoice or bill id allocationmap put('invoice', invoicemap); // as per xero api, the key must always be 'invoice' even when allocating to a bill // add the allocation to the list allocationlist add(allocationmap); // initializing the requestjson data to be passed; map\<string, object> reqjsonmap = new map\<string, object>(); // note creditnoteid can be either an invoice credit note or bill credit note id from xero reqjsonmap put('creditnoteid', 'd6f7a5ff 2297 4697 bdfd f32bb54ce180'); // required replace the id with your credit note id reqjsonmap put('creditnotetype', 'invoice'); // required enter 'invoice' for sales credit notes or 'bill' for bill credit notes // attach allocation details to the request reqjsonmap put('allocations', allocationlist); string reqjson = json serialize(reqjsonmap); // create the final request map 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', 'applycreditnoteallocation'); finalreqmap put('requestjson', reqjson); finalreqmap put('skipdml', false); // skipdml = false → applies the credit note to the invoice/bill and updates related records (credit note, invoice, payment) // required if xero multi org is enabled in breadwinner finalreqmap put('xeroorgid', '!3mt9g'); // replace with your xero org id system debug('request ' + finalreqmap); // placing a request to breadwinner global api map\<string, object> respmap = breadwinnerxeroapi call(finalreqmap); system debug('response ' + respmap); response { "action" "createallocation", "responsejson" { "allocations" \[ { "invoice" { "invoicenumber" null, "invoiceid" "aabd91ad e1ac 496a bb4f 7af066bc9a31" }, "datevariable" "/date(1705276800000+0000)/", "amount" 10 00, "allocationid" "d6c9dff1 a619 470d 8f87 5b28e866245e" } ], "errors" \[], "statuscode" 200 }, "timestamp" 1770268092037, "validrequest" true, "version" "1 0" }
