> For the complete documentation index, see [llms.txt](https://support.onfact.eu/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://support.onfact.eu/more-features/api.md).

# API

The onFact API allows you to automatically call functions within onFact from an external program. For example, an external program can securely retrieve customer lists, create new customers, or generate documents.

\
An “API” is a technical interface that can be accessed from an external program. Accessing the API requires technical knowledge, and you will need to program new functions within the external program to interact with this API.

\
The “API” follows the classic REST architecture. Detailed information about each API function can be found at the following link: [API Reference](https://onfact.stoplight.io/)

{% embed url="<https://onfact.stoplight.io/>" %}

### Authentication

#### &#x20;API Key Authentication

\
The simplest way to authenticate the integration is via an API key. This method is intended for integrations developed specifically for a single company by that company. If you are developing an integration with onFact for multiple users, you should use “oAuth 2.0 authentication.”

\
For authentication via API key, you must add two headers to each request: the `X-SESSION-KEY` and the `X-COMPANY-UUID` headers. These can be found in onFact via the “Personal Settings” menu in the top-right corner.

#### &#x20;Retrieving Invoices

\ <mark style="color:blue;">`GET`</mark> `https://api5.onfact.be/v1/invoices.json`\
Retrieve a list of invoices

#### Headers

| Name           | Type   | Description          |
| -------------- | ------ | -------------------- |
| X-COMPANY-UUID | string | UUID van het bedrijf |
| X-SESSION-KEY  | string | API Key              |

200\
{...}

#### URL Extensions

\
The REST API describes the resource endpoints without an extension; this must still be added to the URL. The extension determines the format in which the resources are displayed. In almost all cases, you will need to add the .json extension to the URL. For documents, you can also use the .pdf, .html, or .xml extensions.

\
To retrieve an invoice in JSON format, you will need to use the following request:

#### &#x20;Retrieve invoice details

<mark style="color:blue;">`GET`</mark> `https://api5.onfact.be/v1/invoices/:id.json`

Retrieve the information from 1 invoice

**Path Parameters**

| Name | Type   | Description |
| ---- | ------ | ----------- |
| id   | string | Factuur ID  |

**Headers**

| Name           | Type   | Description          |
| -------------- | ------ | -------------------- |
| X-SESSION-KEY  | string | API Key              |
| X-COMPANY-UUID | string | UUID Van het bedrijf |

200​

#### Special Functions

\
To simplify API usage, several special functions are built in when creating documents. For example, you can specify an action immediately upon creating a document so that onFact links the newly created document to a customer record or creates a new customer record if one does not exist. To do this, include the `X-ACTIONS` header with the value `FIND-OR-CREATE-CUSTOMER`.&#x20;

Possible values are:

* `CREATE-CUSTOMER`
* `FIND-OR-CREATE-CUSTOMER`
* `UPDATE-CUSTOMER`
* `FIND-PRODUCTS`
* `USE-FIRST-DESCRIPTION`
* `USE-FIRST-TOPTEXT-DESCRIPTION`

Multiple actions can be combined by separating them with a comma.

### &#x20;Create an invoice

<mark style="color:green;">`POST`</mark> `https://api5.onfact.be/v1/invoices/:id.json`

#### Path Parameters

| Name | Type   | Description |
| ---- | ------ | ----------- |
| id   | string | Factuur ID  |

#### Headers

| Name           | Type   | Description             |
| -------------- | ------ | ----------------------- |
| X-ACTIONS      | string | FIND-OR-CREATE-CUSTOMER |
| X-SESSION-KEY  | string | API Key                 |
| X-COMPANY-UUID | string | UUID Van het bedrijf    |

{% tabs %}
{% tab title="200 " %}

```
{
    "id": 123,
    "code": "Created"
}
```

{% endtab %}
{% endtabs %}
