Global API
...
Request
Invoice
Create
2 min
in xero, the "invoice" object includes invoices, bills, and credit notes so, when creating the invoice, set the field "type" with the value "accrec" request // create a map to store all the data of a invoice list\<object> invoicelist = new list\<object>(); map\<string, object> invoicemap = new map\<string, object>(); invoicemap put('type', 'accrec'); invoicemap put('datestring', '2021 11 11t00 00 00'); invoicemap put('duedatestring', '2021 12 06t00 00 00'); invoicemap put('lineamounttypes', 'exclusive'); invoicemap put('status', 'draft'); invoicemap put('emailinvoice', false); // initializing the contact map\<string, object> contactmap = new map\<string, object>(); contactmap put('contactid', 'c84ebb15 0a8d 4145 933f 203e68d014a0'); invoicemap put('contact', contactmap); // initializing the invoice line items list\<object> lineitemlist = new list\<object>(); map\<string, object> lineitemmap = new map\<string, object>(); lineitemmap put('description', 'line item description'); lineitemmap put('unitamount', 100); lineitemmap put('quantity', 10); lineitemmap put('accountcode', '200'); lineitemlist add(lineitemmap); // adding the line items to invoice invoicemap put('lineitems', 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>(); map\<string, object> reqoptions = new map\<string, object>(); finalreqmap put('queryparameters', reqoptions); finalreqmap put('version', '1 0'); finalreqmap put('action', 'createinvoice'); finalreqmap put('requestjson', reqjson); finalreqmap put('skipdml', false); //required, if xero multi org is enabled in breadwinner finalreqmap put('xeroorgid', '!aa00tm'); system debug('request ' + finalreqmap); // placing a request to breadwinner global api map\<string, object> respmap = bread winner breadwinnerxeroapi call(finalreqmap); system debug('response ' + respmap); response { action=createinvoice, responsejson={ "statuscode" 200, "invoices" \[ { "updateddateutc"\ null, "type" "accrec", "totaltax" 0 00, "totaldiscount"\ null, "total" 1000 00, "telephone" "", "subtotal" 1000 00, "status" "draft", "senttocontact"\ false, "salesforcerecordid" "a0k7f00001eft7euas", "reference" "", "purchaseordernumber"\ null, "purchaseorderid"\ null, "payments"\ null, "lineitems" \[ { "unitamount" 100 00, "tracking" \[ ], "taxtype" "output", "taxamount" 0 00, "quantity" 10 0000, "lineitemid" "c638e3bd 3427 485f a5f4 ea8b2b4742d4", "lineamount" 1000 00, "itemcode"\ null, "discountrate"\ null, "description" "line item description", "accountcode" "200" } ], "lineamounttypes" "exclusive", "isdiscounted"\ false, "invoicenumber" "inv 0003", "invoiceid" "c473fb66 9e4c 445a 9855 bba92d6629e9", "haserrors"\ false, "duedatestring" "2021 12 06t00 00 00", "duedate" "/date(1638748800000+0000)/", "deliveryinstructions" "", "deliverydatestring"\ null, "deliverydate"\ null, "deliveryaddress" "", "datevariable" "/date(1636588800000+0000)/", "datestring" "2021 11 11t00 00 00", "currencyrate" 1 0000000000, "currencycode" "inr", "creditnotes"\ null, "contact" { "name" "test contact 1", "contactstatus" "active", "contactid" "3d2df469 b041 4246 a50b 142e87631aa9" }, "brandingthemeid" "8e43230b c814 4435 bdb4 84cad1875e3d", "attentionto" "", "amountpaid" 0 00, "amountdue" 1000 00, "amountcredited" 0 00 } ], "errors" \[ ] }, timestamp=1636616272349, validrequest=true, version=1 0 } create and send in order to send a xero invoice via email after successful creation, use the 'emailinvoice' parameter in the 'requestjson' section of the code provided for creating an invoice simply pass it as shown in the create request example above parameter invoicemap put('emailinvoice', true);