---
title: Create
slug: xero/wxYF-create
description: Learn how to create an invoice in Xero using the "Invoice" object with this comprehensive code instruction document. From setting the invoice type to including important details like date, due date, line items, and contacts, this guide has got you covered
docTags: 
createdAt: 2021-11-02T07:47:04.000Z
---

In Xero, the "Invoice" object includes Invoices, Bills, and Credit Notes. So, when creating the Invoice, set the field "Type" with the value "ACCREC".

:::CodeblockTabs
Request

```json
// 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

```none
{
   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.

:::CodeblockTabs
Parameter

```apex
invoiceMap.put('emailInvoice', true);
```
:::

