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

# Process an invoice automatically

> Retrieve inbox documents, update their information, and book them via the API

Automatically processing an invoice requires three steps: retrieving inbox documents, updating the invoice information,
and booking it.

<Tip>The document inbox holds invoice documents that have been uploaded or received but not yet validated and booked into accounting. Booking an invoice means marking it as validated and ready for accounting.</Tip>

<Steps>
  <Step title="Retrieve inbox documents">
    Use the `GET /cleemy-procurement/services/inbox` endpoint to list documents in the inbox.

    Results are paginated with a maximum of **1000 items per page**. To retrieve all documents, proceed in two passes:

    **1. Get the total count** by requesting only the `count` field along with your filters:

    <CodeGroup>
      ```http Get total count theme={null}
      GET /cleemy-procurement/services/inbox?fields.root=count&{your_filters} HTTP/2
      Host: example.ilucca.net
      Authorization: lucca application={API_KEY}
      Accept: application/json
      ```
    </CodeGroup>

    <Tip>The list of supported filters can be found in the [API Reference](/api-reference/legacy/cleemy-invoices/inbox/inbox-document).</Tip>

    **2. Fetch all pages** by looping from page 1 until the number of items retrieved matches the total count:

    <CodeGroup>
      ```http Fetch a page of results theme={null}
      GET /cleemy-procurement/services/inbox?limit=100&page={pageNumber}&{your_filters} HTTP/2
      Host: example.ilucca.net
      Authorization: lucca application={API_KEY}
      Accept: application/json
      ```
    </CodeGroup>

    <Note>
      Use the **same filters** on both calls so the count matches the actual results.
    </Note>

    <Tip>
      For more details, see the [Inbox-document resource](/api-reference/legacy/cleemy-invoices/inbox/inbox-document) page.
    </Tip>
  </Step>

  <Step title="Update the invoice information">
    Before booking, you may need to update the invoice data (e.g., accounting fields, amounts, or supplier info).
    For this, use `PUT /cleemy-procurement/services/inbox-documents/{id}`:

    <CodeGroup>
      ```http Update an inbox document theme={null}
      PUT /cleemy-procurement/services/inbox-documents/{id} HTTP/2
      Host: example.ilucca.net
      Authorization: lucca application={API_KEY}
      Content-Type: application/json
      Accept: application/json

      {
          "field": "updatedValue"
      }
      ```
    </CodeGroup>

    <Warning>
      This is a `PUT` request — you must send the **complete** resource representation,
      not just the fields you want to change.
    </Warning>
  </Step>

  <Step title="Book the invoice">
    Once the invoice information is complete, book it by calling `POST /cleemy-procurement/services/inbox-documents/{id}/book`.
    **No request body is needed.**

    <CodeGroup>
      ```http Book an inbox document theme={null}
      POST /cleemy-procurement/services/inbox-documents/{id}/book HTTP/2
      Host: example.ilucca.net
      Authorization: lucca application={API_KEY}
      Accept: application/json
      Content-Length: 0
      ```
    </CodeGroup>
  </Step>
</Steps>
