---
title: Create
slug: payments/hdkbchwi8l5qocsk6lkiu
description: Learn how to create an invoice using Apex code with this comprehensive document. Discover step-by-step instructions for generating invoice data, adding items, and making a request to the powerful Breadwinner Global API. Find out how to retrieve essential
docTags: 
createdAt: 2023-11-29T05:49:47.376Z
---

To create an Invoice in Square, use the action “CreateInvoice” and pass the Invoice data in the RequestJSON under “Invoices.”

:::hint{type="info"}
Note: You can only create one record at a time.
:::

The following is an example of creating a Square Invoice where we are setting every possible field (See[﻿](https://app.archbee.io/docs/-LIHUUnv_7XNQrtzHsKkC/hnjmkN99QxWdEafyYIFSq)﻿ [Invoice - Square](docId\:V6qnF8xCSlO0VKSt79DV5) for all the available fields). The response will return the response from Square, which includes the  Invoice ID (*internalId*) plus the newly created Salesforce Invoice ID (*salesforceId*).

:::CodeblockTabs
```apex
Map<String, Object> invoiceData = new Map<String, Object>();
invoiceData.put('processorCustomerId', 'processorCustomerId');
invoiceData.put('dueDate', '2023-06-12');

List<object> items = new List<object>();
Map<String, Object> itemData = new Map<String, Object>();
itemData.put('processorPriceId', 'processorPriceId'); 
itemData.put('quantity', 3); 
items.add(itemData);
invoiceData.put('items', items); 

//  Initializing the RequestJSON Data to be passed.
Map<String, Object> requestJSONMap = new Map<String, Object>();
requestJSONMap.put('invoices', new List<Object>{invoiceData});
String reqJSON = JSON.serialize(requestJSONMap);

Map<String, Object> reqObj = new Map<String, Object>();
reqObj.put('version','1.0');
reqObj.put('action','CreateInvoice');
reqObj.put('processorId', 'processorId');
reqObj.put('requestJSON',reqJSON);

//  Placing a request to Breadwinner Global API
Map<String,Object> resp = bw_payments.BreadwinnerPaymentsAPI.call(reqObj);
System.debug(resp);

```

```json
{
  Action=CreateInvoice,
  Version=1.0,
  responseJSON={
    "invoices": [
    {
      "status": "UNPAID",
      "salesforceId": "salesforceId",
      "salesforceContact": null,
      "salesforceAccount": null,
      "processorPaymentMethodId": null,
      "processorOrgId": "processorOrgId",
      "processorInvoiceId": "processorInvoiceId",
      "processorCustomerId": null,
      "items": [
        {
          "unitAmountDecimal": 20,
          "unitAmount": 20,
          "salesforceSubscriptionId": null,
          "salesforcePriceId": "salesforcePriceId",
          "salesforceInvoiceId": null,
          "salesforceId": "salesforceId",
          "quantity": 3,
          "processorSubscriptionId": null,
          "processorPriceId": null,
          "processorInvoiceId": "processorInvoiceId",
          "processorId": "processorId",
          "name": null,
          "metadataAsString": null,
          "errorMessage": null,
          "description": null,
          "deleted": null,
          "chargeCurrency": "EUR",
          "amount": 60
        }
      ],
      "errorMessage": null,
      "dueDate": "2023-06-12T12:15:39.507Z",
      "description": null,
      "createdVia": "Breadwinner",
      "createdDateInProcessor": "2023-06-08T12:15:38.000Z",
      "collectionMethod": "EMAIL"
    }
  ]
  }, 
  statusCode=200, 
  timestamp=1686226539974, 
  validRequest=true
}
```
:::

