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

# Create Invoice

> Create an invoice for billing customers

<Note>
  This endpoint creates a new invoice for billing customers. Invoices can be sent immediately or scheduled for future delivery.
</Note>

## Authentication

This endpoint requires a valid API key with `invoices:write` permissions.

```bash theme={null}
Authorization: Bearer YOUR_API_KEY
```

## Request Body

<ParamField body="customer_id" type="string" required>
  Customer ID to bill
</ParamField>

<ParamField body="invoice_number" type="string">
  Custom invoice number (auto-generated if not provided)
</ParamField>

<ParamField body="issue_date" type="string" required>
  Invoice issue date (ISO 8601)
</ParamField>

<ParamField body="due_date" type="string" required>
  Payment due date (ISO 8601)
</ParamField>

<ParamField body="currency" type="string" required>
  ISO 4217 currency code
</ParamField>

<ParamField body="line_items" type="array" required>
  Invoice line items

  <Expandable title="Line item properties">
    <ParamField body="description" type="string" required>
      Item description
    </ParamField>

    <ParamField body="quantity" type="number" required>
      Quantity
    </ParamField>

    <ParamField body="unit_price" type="integer" required>
      Unit price in cents
    </ParamField>

    <ParamField body="product_id" type="string">
      Associated product ID
    </ParamField>

    <ParamField body="tax_rate" type="number">
      Tax rate as decimal (e.g., 0.08 for 8%)
    </ParamField>

    <ParamField body="discount_rate" type="number">
      Discount rate as decimal
    </ParamField>

    <ParamField body="account_code" type="string">
      Accounting code
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="billing_address" type="object">
  Billing address

  <Expandable title="Address properties">
    <ParamField body="line1" type="string" required>
      Street address
    </ParamField>

    <ParamField body="line2" type="string">
      Apartment/Suite
    </ParamField>

    <ParamField body="city" type="string" required>
      City
    </ParamField>

    <ParamField body="state" type="string" required>
      State/Province
    </ParamField>

    <ParamField body="postal_code" type="string" required>
      Postal code
    </ParamField>

    <ParamField body="country" type="string" required>
      Country code
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="payment_terms" type="string">
  Payment terms (e.g., "Net 30", "Due on receipt")
</ParamField>

<ParamField body="notes" type="string">
  Invoice notes or memo
</ParamField>

<ParamField body="send_email" type="boolean">
  Whether to email invoice to customer (default: false)
</ParamField>

<ParamField body="metadata" type="object">
  Additional custom fields
</ParamField>

### Response

Returns the created invoice.

<RequestExample>
  ```bash cURL theme={null}
  curl --location --request POST 'https://api.stateset.com/v1/invoices' \
  --header 'Content-Type: application/json' \
  --header 'Authorization: Bearer YOUR_API_KEY' \
  --data-raw '{
      "customer_id": "cust_abc123",
      "issue_date": "2024-01-19",
      "due_date": "2024-02-18",
      "currency": "USD",
      "line_items": [
          {
              "description": "Professional Services - January 2024",
              "quantity": 40,
              "unit_price": 15000,
              "tax_rate": 0.08
          },
          {
              "description": "Software License",
              "quantity": 5,
              "unit_price": 9900,
              "product_id": "prod_xyz789"
          }
      ],
      "payment_terms": "Net 30",
      "send_email": true
  }'
  ```

  ```javascript Node.js theme={null}
  const invoice = await stateset.invoices.create({
    customer_id: "cust_abc123",
    issue_date: "2024-01-19",
    due_date: "2024-02-18",
    currency: "USD",
    line_items: [
      {
        description: "Professional Services - January 2024",
        quantity: 40,
        unit_price: 15000,
        tax_rate: 0.08
      },
      {
        description: "Software License",
        quantity: 5,
        unit_price: 9900,
        product_id: "prod_xyz789"
      }
    ],
    payment_terms: "Net 30",
    send_email: true
  });
  ```
</RequestExample>

<ResponseExample>
  ```json Response theme={null}
  {
    "id": "inv_0901f083-aa1c-43c5-af5c-0a9d2fc64e30",
    "object": "invoice",
    "invoice_number": "INV-2024-0001",
    "status": "sent",
    "customer_id": "cust_abc123",
    "issue_date": "2024-01-19",
    "due_date": "2024-02-18",
    "currency": "USD",
    "subtotal": 649500,
    "tax_amount": 48000,
    "total_amount": 697500,
    "amount_due": 697500,
    "amount_paid": 0,
    "line_items": [
      {
        "id": "li_123456",
        "description": "Professional Services - January 2024",
        "quantity": 40,
        "unit_price": 15000,
        "amount": 600000,
        "tax_rate": 0.08,
        "tax_amount": 48000
      },
      {
        "id": "li_123457",
        "description": "Software License",
        "quantity": 5,
        "unit_price": 9900,
        "amount": 49500,
        "product_id": "prod_xyz789",
        "tax_rate": 0,
        "tax_amount": 0
      }
    ],
    "payment_terms": "Net 30",
    "created_at": "2024-01-19T10:00:00Z",
    "sent_at": "2024-01-19T10:01:00Z",
    "pdf_url": "https://invoices.stateset.com/inv_0901f083-aa1c-43c5-af5c-0a9d2fc64e30.pdf"
  }
  ```
</ResponseExample>
