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 request // 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); response { action=createcreditnote, responsejson={ "statuscode" 200, "creditnotes" \[ { "creditnoteid" "dac2c670 e3cb 41ff a6a5 ff2ac9149e73", "payments" \[], "id" "dac2c670 e3cb 41ff a6a5 ff2ac9149e73", "haserrors" false, "currencyrate" 1 0000000000, "type" "accpaycredit", "reference" "", "remainingcredit" 100 00, "allocations" \[], "contact" { "contactid" "021b18f8 b62f 4d8a 889e 71fd5427892a", "contactstatus" "active", "name" "young bros transport", "emailaddress" "rog\@ybt co", "addresses" \[ { "addresstype" "street", "city" "", "region" "", "postalcode" "", "country" "" }, { "addresstype" "pobox", "addressline1" "p o box 5678\r\n", "city" "oaktown", "region" "", "postalcode" "1235", "country" "" } ], "phones" \[ { "phonetype" "mobile", }, { "phonetype" "default", }, { "phonetype" "fax", }, { "phonetype" "ddi", } ], "updateddateutc" "\\/date(1769623421917+0000)\\/", "contactgroups" \[], "contactpersons" \[], "hasvalidationerrors" false }, "datestring" "2026 03 11t00 00 00", "date" "\\/date(1773187200000+0000)\\/", "status" "authorised", "lineamounttypes" "inclusive", "lineitems" \[ { "description" "cn inv line item description final check", "unitamount" 100 00, "taxtype" "output", "taxamount" 7 62, "lineamount" 100 00, "accountcode" "200", "tracking" \[], "quantity" 1 0000, "lineitemid" "0f50a00c 5934 4d38 9ac1 1dc7698ade99", "accountid" "d1ebb97b d207 4ccb 9ab6 8a466a8b4d39", "validationerrors" \[] } ], "subtotal" 92 38, "totaltax" 7 62, "total" 100 00, "updateddateutc" "\\/date(1770903590453+0000)\\/", "currencycode" "usd" } ], "errors" \[ ] }, timestamp=1636616272349, validrequest=true, version=1 0 }
