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

# Create Invoice

> Create a new invoice.

[The Invoices Data Model](https://docs.rootfi.dev/api-reference/invoices/overview) is designed to standardise and `simplify` the handling of invoice-related information across different accounting platforms.

<RequestExample>
  ```bash cURL theme={null}
  curl --request POST \
    --url https://api.rootfi.dev/v3/accounting/invoices \
    --header 'Content-Type: application/json' \
    --header 'api_key: <api-key>' \
    --data '{
    "company_id": 1,
    "data": [
      {
        "contact_id": "123456",
        "document_number": "ROOTFI01",
        "posted_date": "2021-09-28T15:00:00.000Z",
        "due_date": "2021-09-28T15:00:00.000Z",
        "memo": "Test Invoice",
        "line_items": [
          {
            "account_id": "123456",
            "quantity": 1,
            "item_id": "123456",
            "tax_id": "123456",
            "unit_amount": 100,
            "total_discount": 0,
            "description": "Test Item"
          }
        ]
      }
    ]
  }'
  ```

  ```javascript NodeJS theme={null}
  import { RootFiClient } from "rootfi-api";
  const rootfi = new RootFiClient({ apiKey: "<api_key>" });

  await rootfi.accounting.invoice.create({
    company_id: 1,
    data: [
      {
        contact_id: "123456",
        document_number: "ROOTFI01",
        posted_date: "2021-09-28T15:00:00.000Z",
        due_date: "2021-09-28T15:00:00.000Z",
        memo: "Test Invoice",
        line_items: [
          {
            account_id: "123456",
            quantity: 1,
            item_id: "123456",
            tax_id: "123456",
            unit_amount: 100,
            total_discount: 0,
            description: "Test Item",
          },
        ],
      },
    ],
  });
  ```
</RequestExample>


## OpenAPI

````yaml POST /accounting/invoices
openapi: 3.0.1
info:
  title: rootfi
  version: v2
servers:
  - url: https://api.rootfi.dev
    description: Production
security: []
paths:
  /accounting/invoices:
    post:
      tags:
        - AccountingInvoice
      summary: Create Invoice
      description: Add an invoice.
      operationId: accounting_invoice_create
      parameters: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/accountingtypesCreateInvoiceRequest'
            examples:
              Example1:
                value:
                  company_id: 1
                  data:
                    - contact_id: '123456'
                      document_number: ROOTFI01
                      posted_date: '2021-09-28T15:00:00.000Z'
                      due_date: '2021-09-28T15:00:00.000Z'
                      memo: Test Invoice
                      line_items:
                        - account_id: '123456'
                          quantity: 1
                          item_id: '123456'
                          tax_id: '123456'
                          unit_amount: 100
                          total_discount: 0
                          description: Test Item
      responses:
        '200':
          description: ''
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/accountingtypesCreateInvoicesResponse'
              examples:
                Example1:
                  value:
                    data:
                      status: SUCCESS
                      upload_job_id: aXI9pUDA5T7E2LS
                      data:
                        - job_id: xQm2K441VosP8W4
                          status: success
                          response:
                            tax_amount: 34.2
                            document_number: INV82897
                            total_discount: 10
                            due_date: '2024-03-19T00:00:00.000Z'
                            memo: Tvoice
                            contact_id: '3770712000000080150'
                            currency_rate: 1
                            updated_at: '2023-11-01T00:00:00.000Z'
                            total_amount: 224.2
                            sales_order_ids: []
                            platform_id: '3770712000001676083'
                            sub_total: 190
                            amount_due: 224.2
                            posted_date: '2023-03-17T00:00:00.000Z'
                            currency_id: '3770712000000000099'
                            status: DRAFT
                            raw_data:
                              platform_id: '123456'
                              nominal_code: Rootfi 01
                              name: Test Account
                              description: Test Description
                              category: LIABILITY
                              sub_category: Long Term Liabilities
                              status: ACTIVE
                          error: null
                    request_timestamp: '2021-09-28T15:00:00.000Z'
                    response_timestamp: '2021-09-28T15:00:00.000Z'
                    request_id: 7a1c0e42-9f85-4d6e-bb5d-358a72913c0b
      security:
        - ApiKeyAuth: []
components:
  schemas:
    accountingtypesCreateInvoiceRequest:
      title: accountingtypesCreateInvoiceRequest
      type: object
      description: Create invoices for the company
      properties:
        company_id:
          type: integer
          example: 1
        data:
          type: array
          items:
            $ref: '#/components/schemas/accountingtypesInvoicesWriteAndUpdateRequest'
      required:
        - company_id
        - data
    accountingtypesCreateInvoicesResponse:
      title: accountingtypesCreateInvoicesResponse
      type: object
      properties: {}
      allOf:
        - $ref: '#/components/schemas/accountingtypesFinalCreateInvoicesResponse'
        - $ref: '#/components/schemas/timestamp'
    accountingtypesInvoicesWriteAndUpdateRequest:
      title: accountingtypesInvoicesWriteAndUpdateRequest
      type: object
      properties:
        line_items:
          type: array
          items:
            $ref: '#/components/schemas/LineItems'
          nullable: true
          description: Array of Invoice Line items associated with the invoice
        raw_data:
          type: object
          additionalProperties: true
          nullable: true
          description: >-
            A JSON containing fields that you can directly pass to the
            accounting platform.
      allOf:
        - $ref: '#/components/schemas/accountingtypesInvoicesAllResponsesCommonFields'
    accountingtypesFinalCreateInvoicesResponse:
      title: accountingtypesFinalCreateInvoicesResponse
      type: object
      properties:
        data:
          $ref: '#/components/schemas/accountingtypesCreateInvoiceResponseData'
      required:
        - data
    timestamp:
      title: timestamp
      type: object
      properties:
        request_timestamp:
          type: string
          format: date-time
          description: The time at which the request was received by the server
        response_timestamp:
          type: string
          format: date-time
          description: The time at which the response was sent by the server
        request_id:
          type: string
          description: The unique ID of the request
      required:
        - request_timestamp
        - response_timestamp
        - request_id
    LineItems:
      title: LineItems
      type: object
      properties:
        account_id:
          type: string
          nullable: true
          description: The ID of the account in the accounting platform
        quantity:
          type: number
          format: double
          nullable: true
          description: The quantity of the item
        item_id:
          type: string
          nullable: true
          description: The ID of the item in the accounting platform
        tax_id:
          type: string
          nullable: true
          description: The ID of the tax in the accounting platform
        unit_amount:
          type: number
          format: double
          nullable: true
          description: The unit amount of the item
        total_discount:
          type: number
          format: double
          nullable: true
          description: The total discount on the item
        description:
          type: string
          nullable: true
          description: The description of the item
        tracking_category_ids:
          type: array
          items:
            type: string
          nullable: true
          description: The IDs of the tracking categories in the accounting platform
    accountingtypesInvoicesAllResponsesCommonFields:
      title: accountingtypesInvoicesAllResponsesCommonFields
      type: object
      properties:
        contact_id:
          type: string
          nullable: true
          description: >-
            The Accounting Platform’s unique ID for the contact who receives
            this invoice
        currency_id:
          type: string
          nullable: true
          description: The ISO-4217 currency code of the invoice
        document_number:
          type: string
          nullable: true
          description: Reference document number for the invoice
        posted_date:
          type: string
          nullable: true
          description: Date of the invoice as recorded by the accounting platform
        due_date:
          type: string
          nullable: true
          description: The due date for the invoice as an ISO 8601 timestamp
        memo:
          type: string
          nullable: true
          description: Description of the invoice
    accountingtypesCreateInvoiceResponseData:
      title: accountingtypesCreateInvoiceResponseData
      type: object
      properties:
        data:
          type: array
          items:
            $ref: '#/components/schemas/accountingtypesinvoicesResponse'
      required:
        - data
      allOf:
        - $ref: '#/components/schemas/SuccessResponse'
    accountingtypesinvoicesResponse:
      title: accountingtypesinvoicesResponse
      type: object
      properties:
        response:
          $ref: >-
            #/components/schemas/accountingtypesInvoicesWriteAndUpdateResponseFields
        error:
          $ref: '#/components/schemas/ErrorObject'
          nullable: true
          description: The error message if the job failed.
      required:
        - response
      allOf:
        - $ref: '#/components/schemas/JobSuccessResponse'
    SuccessResponse:
      title: SuccessResponse
      type: object
      properties:
        status:
          $ref: '#/components/schemas/Status'
          description: The status of the job.
        upload_job_id:
          type: string
          description: The ID of the job.
      required:
        - status
        - upload_job_id
    accountingtypesInvoicesWriteAndUpdateResponseFields:
      title: accountingtypesInvoicesWriteAndUpdateResponseFields
      type: object
      properties:
        raw_data:
          type: object
          additionalProperties: true
          nullable: true
          description: >-
            The raw JSON response we get from the accounting platform for that
            data
      allOf:
        - $ref: '#/components/schemas/accountingtypesInvoicesResponseField'
    ErrorObject:
      title: ErrorObject
      type: object
      properties:
        code:
          type: string
        message:
          type: string
        platform_error:
          type: string
        raw_data:
          type: object
          additionalProperties: true
          nullable: true
      required:
        - code
        - message
        - platform_error
    JobSuccessResponse:
      title: JobSuccessResponse
      type: object
      properties:
        job_id:
          type: string
          description: The ID of the job.
        status:
          $ref: '#/components/schemas/JobResponseStatus'
          description: The status of the job.
      required:
        - job_id
        - status
    Status:
      title: Status
      type: string
      enum:
        - SUCCESS
        - FAILED
        - CREATED
        - RUNNING
    accountingtypesInvoicesResponseField:
      title: accountingtypesInvoicesResponseField
      type: object
      properties:
        currency_rate:
          type: number
          format: double
          nullable: true
          description: Rate between the currency of the payment and the base currency
        status:
          $ref: '#/components/schemas/ArtifactStatus'
          nullable: true
          description: The status of the invoice.
        tax_amount:
          type: number
          format: double
          nullable: true
          description: Total tax amount levied on the invoice
        total_discount:
          type: number
          format: double
          nullable: true
          description: Total value of discounts applied to the invoice
        total_amount:
          type: number
          format: double
          nullable: true
          description: Total value of the invoice
        sales_order_ids:
          type: array
          items:
            type: string
          nullable: true
          description: Array of linked Sales Orders IDs associated with this invoice
        sub_total:
          type: number
          format: double
          nullable: true
          description: Total pre tax value of the invoice
        amount_due:
          type: number
          format: double
          nullable: true
          description: Total amount pending for the invoice
        updated_at:
          type: string
          nullable: true
          description: Date the record was last updated in the accounting platform.
      allOf:
        - $ref: '#/components/schemas/accountingtypesInvoicesPlatformId'
        - $ref: '#/components/schemas/accountingtypesInvoicesAllResponsesCommonFields'
    JobResponseStatus:
      title: JobResponseStatus
      type: string
      enum:
        - success
        - failed
    ArtifactStatus:
      title: ArtifactStatus
      type: string
      enum:
        - DRAFT
        - SUBMITTED
        - PARTIALLY_PAID
        - PAID
        - OVERDUE
        - VOID
        - UNKNOWN
    accountingtypesInvoicesPlatformId:
      title: accountingtypesInvoicesPlatformId
      type: object
      properties:
        platform_id:
          type: string
          description: The ID that the accounting platform uses to identify this invoice
      required:
        - platform_id
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: api_key

````