> ## Documentation Index
> Fetch the complete documentation index at: https://docs.automate.ax/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Automate.ax automations are TypeScript programs.
> Use Bun for installation and command examples.
> Use Automate.ax for the product name and automate.ax for the package, CLI, and domain.
> Treat documented public APIs as current; do not invent transitional or deprecated names.

# Create Invoice

> Creates a draft [invoice](entity:Invoice) for an order created using the Orders API.

`square.createInvoice` creates a draft [invoice](entity:Invoice) for an order created using the Orders API.

## Example

```ts automations/square-create-invoice.automation.ts theme={null}
import { automation, onDashboardRun } from "automate.ax"
import { square } from "automate.ax/square"

export default automation("Create Square Invoice", () => {
  onDashboardRun({ title: "Create Square Invoice" })

  square.createInvoice({
    invoice: {
      locationId: "ES0RJRZYEC39A",
      orderId: "CAISENgvlJ6jLWAzERDzjyHVybY",
      primaryRecipient: {
        customerId: "JDKYHBWT1D4F8MFH63DBMEN8Y4",
      },
      paymentRequests: [
        {
          requestType: "BALANCE",
          dueDate: "2030-01-24",
          tippingEnabled: true,
          automaticPaymentSource: "NONE",
          reminders: [
            {
              relativeScheduledDays: -1,
              message: "Your invoice is due tomorrow",
            },
          ],
        },
      ],
      deliveryMethod: "EMAIL",
      invoiceNumber: "inv-100",
      title: "Event Planning Services",
      description: "We appreciate your business!",
      scheduledAt: "2030-01-13T10:00:00Z",
      acceptedPaymentMethods: {
        card: true,
        squareGiftCard: false,
        bankAccount: false,
        buyNowPayLater: false,
        cashAppPay: false,
      },
      customFields: [
        {
          label: "Event Reference Number",
          value: "Ref. #1234",
          placement: "ABOVE_LINE_ITEMS",
        },
        {
          label: "Terms of Service",
          value: "The terms of service are...",
          placement: "BELOW_LINE_ITEMS",
        },
      ],
      saleOrServiceDate: "2030-01-24",
      storePaymentMethodEnabled: false,
    },
    idempotencyKey: "ce3748f9-5fc1-4762-aa12-aae5e843f1f4",
  })
})
```

## Inputs

Every input accepts a compatible signal. It requires `INVOICES_WRITE` and `ORDERS_WRITE`.

| Field            | Type             | Required | Default | Description                                                                                                                                                                                                                                                                                                                 |
| ---------------- | ---------------- | -------- | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `invoice`        | `Square.Invoice` | Yes      | —       | The invoice to create.                                                                                                                                                                                                                                                                                                      |
| `idempotencyKey` | `string`         | No       | —       | A unique string that identifies the `CreateInvoice` request. If you do not provide `idempotency_key` (or provide an empty string as the value), the endpoint treats each request as independent. For more information, see [Idempotency](https://developer.squareup.com/docs/build-basics/common-api-patterns/idempotency). |

Use the official [CreateInvoice reference](https://developer.squareup.com/reference/square/invoices-api/create-invoice) for provider field semantics and limits.

## Output

Returns the official `Square.CreateInvoiceResponse` response as a codec-safe object. Square integer money amounts remain `bigint` values.
