# Expenses

> Markdown edition of https://api.fiz.co/docs/api/expenses. Português: https://api.fiz.co/docs/api/expenses.md?lang=pt. Index: https://api.fiz.co/llms.txt

Purchase documents imported from e-Fatura, with their category and VAT. Read-only. 2 operations.

## Expense summary

GET `/expenses/stats`

Counts and totals of the expenses for a year, quarter or date range: categorised and still to categorise, business and personal, refusals and conflicts with the e-Fatura portal, deductible VAT, and the date of the last e-Fatura import.

Authentication: an API key (`x-api-key`) or an OAuth access token.

### Parameters

| Name | In | Type | Description |
| --- | --- | --- | --- |
| `year` | query | number | Fiscal year, by emission date. Required unless fromDate and toDate are given. |
| `quarter` | query | number | Quarter (1-4) of the given year. Without a quarter, the whole year. |
| `fromDate` | query | string | Period start, inclusive (YYYY-MM-DD), instead of year and quarter. An expense counts by its accounting date (accountingDate) or, when it has none, by its emission date. |
| `toDate` | query | string | Period end, inclusive (YYYY-MM-DD) |

**curl**

```shell
curl 'https://api.fiz.co/expenses/stats' \
  --header "x-api-key: $FIZ_API_KEY"
```

**TypeScript**

```ts
import { Fiz } from '@fiz-co/sdk';

const fiz = new Fiz(); // reads FIZ_API_KEY
const result = await fiz.expenses.stats();
```

**Python**

```python
from fiz_sdk import Fiz

fiz = Fiz()  # reads FIZ_API_KEY
result = fiz.expenses.stats()
```

**PHP**

```php
<?php
require 'vendor/autoload.php';

$fiz = new Fiz\Fiz(); // reads FIZ_API_KEY
$result = $fiz->expenses->stats();
```

### Response `200`

Expense summary returned successfully

| Field | Type | Description |
| --- | --- | --- |
| `totalCount` | number | Total number of expenses |
| `categorizedCount` | number | Categorised expenses |
| `uncategorizedCount` | number | Expenses still to categorise |
| `uncategorizedWithoutPortalAnswerCount` | number | Expenses still to categorise with no answer on the e-Fatura portal either: the ones nobody has answered anywhere |
| `businessCount` | number | Business expenses |
| `personalCount` | number | Personal expenses |
| `syncFailedCount` | number | Expenses whose categorisation the e-Fatura portal refused and the person can fix |
| `syncLockedCount` | number | Refusals in a period the portal has closed: shown, nothing can be re-sent; not part of syncFailedCount |
| `pendingSendCount` | number | Categorisations FIZ will still send to the e-Fatura portal automatically |
| `efaturaSendPending` | boolean | A send of categorisations to the e-Fatura portal is queued or running for the period year |
| `conflictCount` | number | Expenses where FIZ and the e-Fatura portal hold different answers; a person picks one in the app |
| `portalDisagreesCount` | number | Expenses deducted in a filed quarter that the e-Fatura portal now contradicts |
| `totalAmount` | number | Total including VAT, in euros |
| `totalVat` | number | Total VAT, in euros |
| `businessVatDeductible` | number | Deductible VAT on business expenses, in euros |
| `personalCategoryTotals` | object\[\] | Totals per personal category (no IRS deduction applied) |
| `personalCategoryTotals[].category` | string | Personal category — One of: `ARTS`, `BOOKS`, `EDUCATION`, `ELDERLY_CARE`, `GYMS`, `HAIRDRESSER`, `HEALTH`, `HOUSING`, `MOTORCYCLE`, `MUSEUMS`, `NEWSPAPERS`, `OTHER`, `PUBLIC_TRANSPORT`, `RESTAURANT`, `VEHICLE_REPAIR`, `VETERINARY` |
| `personalCategoryTotals[].count` | number | Number of expenses |
| `personalCategoryTotals[].amount` | number | Total including VAT, in euros |
| `personalCategoryTotals[].vatAmount` | number | VAT included in the total, in euros |
| `lastSyncDate` | string · can be null | Date of the last expense import from e-Fatura. The most recent expenses may not be in FIZ yet. |

### Errors

-   `400` Invalid parameters
-   `401` Unauthorized - API key missing or invalid
-   `429` The OAuth connection’s request limit is reached. Nothing was executed: repeat the same request after Retry-After seconds.

## List expenses

GET `/expenses`

Expenses (purchase invoices) imported from e-Fatura for a year, quarter or date range, newest first, with their categorisation and deductible VAT. The period works as in GET /expenses/stats. Read-only: the e-Fatura import and categorisation happen in the FIZ app. GET /expenses/stats gives the date of the last import.

Authentication: an API key (`x-api-key`) or an OAuth access token.

### Parameters

| Name | In | Type | Description |
| --- | --- | --- | --- |
| `year` | query | number | Fiscal year, by emission date. Required unless fromDate and toDate are given. |
| `quarter` | query | number | Quarter (1-4) of the given year. Without a quarter, the whole year. |
| `fromDate` | query | string | Period start, inclusive (YYYY-MM-DD), instead of year and quarter. An expense counts by its accounting date (accountingDate) or, when it has none, by its emission date. |
| `toDate` | query | string | Period end, inclusive (YYYY-MM-DD) |
| `expenseType` | query | string | Filter by expense type (business or personal) — One of: `BUSINESS`, `PERSONAL` |
| `isCategorized` | query | boolean | true: only categorised expenses; false: only those still to categorise |
| `syncFailed` | query | boolean | true: only expenses whose categorisation the e-Fatura portal refused |
| `search` | query | string | Search by supplier name or NIF, or document number |
| `offset` | query | number | Number of records to skip (offset) |
| `limit` | query | number | Maximum number of records to return (at most 500) |

**curl**

```shell
curl 'https://api.fiz.co/expenses' \
  --header "x-api-key: $FIZ_API_KEY"
```

**TypeScript**

```ts
import { Fiz } from '@fiz-co/sdk';

const fiz = new Fiz(); // reads FIZ_API_KEY
const result = await fiz.expenses.list();
```

**Python**

```python
from fiz_sdk import Fiz

fiz = Fiz()  # reads FIZ_API_KEY
result = fiz.expenses.list()
```

**PHP**

```php
<?php
require 'vendor/autoload.php';

$fiz = new Fiz\Fiz(); // reads FIZ_API_KEY
$result = $fiz->expenses->list();
```

### Response `200`

Expense list returned successfully

| Field | Type | Description |
| --- | --- | --- |
| `[].id` | string | FIZ expense identifier |
| `[].efaturaDocumentId` | string | e-Fatura document identifier |
| `[].number` | string · can be null | Supplier's document number |
| `[].atcud` | string · can be null | Document ATCUD |
| `[].documentType` | string · can be null | e-Fatura document type (FT, FS, FR, NC, ND) |
| `[].date` | string · can be null | Emission date (YYYY-MM-DD) |
| `[].accountingDate` | string · can be null | Accounting date (YYYY-MM-DD): the first open day when the emission's period was already closed. Null when none was assigned; the emission date then applies. |
| `[].supplier` | object | Supplier |
| `[].supplier.nif` | string | Supplier NIF |
| `[].supplier.name` | string | Supplier name |
| `[].supplier.activityCode` | string · can be null | Supplier's e-Fatura activity sector code |
| `[].supplier.activity` | string · can be null | Supplier's e-Fatura activity sector |
| `[].total` | number | Total including VAT, in euros |
| `[].taxBase` | number | Taxable base, in euros |
| `[].vat` | number | VAT, in euros |
| `[].vatBreakdown` | object\[\] | Document VAT per rate, as reported to e-Fatura (stamp duty excluded) |
| `[].vatBreakdown[].rateType` | string | VAT rate type (NOR, INT, RED, ISE) |
| `[].vatBreakdown[].rate` | number | VAT rate (%) |
| `[].vatBreakdown[].taxBase` | number | Taxable base at this rate, in euros |
| `[].vatBreakdown[].vat` | number | VAT at this rate, in euros |
| `[].isForeignDocument` | boolean | Document issued by a foreign supplier |
| `[].creditNoteParentId` | string · can be null | For credit notes: the expense (invoice) the note corrects, if confirmed |
| `[].categorization` | object | Expense categorisation |
| `[].categorization.isCategorized` | boolean | Whether the expense is already categorised |
| `[].categorization.source` | string · can be null | Categorisation source: AUTO (suggested by FIZ from the supplier activity), USER (chosen by a person in FIZ) or PORTAL (the answer given on the e-Fatura portal) — One of: `AUTO`, `USER`, `PORTAL` |
| `[].categorization.expenseType` | string · can be null | Business or personal expense — One of: `BUSINESS`, `PERSONAL` |
| `[].categorization.businessCategory` | string · can be null | Business category — One of: `BANKING`, `EDUCATION`, `ENTERTAINMENT`, `EQUIPMENT`, `EVENTS`, `FACILITIES`, `FUEL`, `MARKETING`, `OTHER`, `PARKING`, `PROFESSIONAL`, `RESALE`, `SOFTWARE`, `SUPPLIES`, `TELECOMMUNICATIONS`, `TRANSPORT`, `TRAVEL`, `VEHICLE` |
| `[].categorization.personalCategory` | string · can be null | Personal category (IRS tax deduction, art. 78 CIRS) — One of: `ARTS`, `BOOKS`, `EDUCATION`, `ELDERLY_CARE`, `GYMS`, `HAIRDRESSER`, `HEALTH`, `HOUSING`, `MOTORCYCLE`, `MUSEUMS`, `NEWSPAPERS`, `OTHER`, `PUBLIC_TRANSPORT`, `RESTAURANT`, `VEHICLE_REPAIR`, `VETERINARY` |
| `[].categorization.businessPercentage` | number · can be null | Business use percentage (100 = fully business) |
| `[].categorization.catalogCategoryId` | string · can be null | Bookkeeping catalogue category the person chose; businessCategory is the grouping derived from it. The value "uncategorized" is a business expense with no category chosen, which deducts no VAT. |
| `[].vatDeduction` | object · can be null | Deductible VAT computed by the VAT return engine. Null when there is nothing to deduct (not categorised, personal expense). |
| `[].vatDeduction.deductibleVat` | number | Deductible VAT in euros, business share already applied. Do not add up across expenses: the period total is in the periodic VAT return. |
| `[].vatDeduction.rate` | number · can be null | Deduction rate (0 to 1). Null when the document splits across several rates. |
| `[].vatDeduction.ivaField` | string · can be null | Field of table 06 of the periodic VAT return — One of: `CAMPO_20`, `CAMPO_21`, `CAMPO_22`, `CAMPO_23`, `CAMPO_24`, `REVERSE_CHARGE_EU`, `REVERSE_CHARGE_NON_EU`, `ZERO` |
| `[].vatDeduction.restrictionCode` | string · can be null | Legal rule limiting the deduction, when below 100% — One of: `ART9_EXEMPT`, `ART20_EXEMPT_ACTIVITY`, `ART20_NOT_AN_INPUT`, `ART21_1A_VEHICLE`, `ART21_1B_HALF`, `ART21_1B_PETROL`, `ART21_1C_PARKING`, `ART21_1C_TRANSPORT`, `ART21_1D_HOSPITALITY`, `ART21_1D_REPRESENTATION`, `ART21_1E_ENTERTAINMENT`, `ART21_2DE_CONGRESS`, `ART21_2FG_PRICE_CAP`, `ART23_PRORATA`, `CATALOG_UNMAPPED`, `NO_INPUT_VAT`, `REGIME_ART9_EXEMPT`, `REGIME_ART53_EXEMPT` |
| `[].efaturaSync` | object | Categorisation reported to the e-Fatura portal |
| `[].efaturaSync.syncedAt` | string · can be null | When the categorisation was reported to the e-Fatura portal |
| `[].efaturaSync.failed` | boolean | The e-Fatura portal refused the categorisation |
| `[].efaturaSync.locked` | boolean | The refusal sits in a period the portal has closed: shown, but nothing can be re-sent |
| `[].efaturaSync.error` | string · can be null | The e-Fatura portal's refusal message, as received |
| `[].efaturaSync.conflict` | object · can be null | FIZ and the e-Fatura portal hold different answers and it is unknown which is newer; a person picks one in the app |
| `[].efaturaSync.conflict.since` | string | Since when the conflict exists |
| `[].efaturaSync.conflict.portalUsageType` | string · can be null | Scope given on the portal (the professional-activity answer) |
| `[].efaturaSync.conflict.portalCategory` | string · can be null | Category given on the portal |
| `[].efaturaSync.portalDisagreesAt` | string · can be null | Since when the portal contradicts an expense already deducted in a filed quarter (the portal answer was not applied) |
| `[].createdAt` | string | Record created at |
| `[].updatedAt` | string | Record last updated at |

### Errors

-   `400` Invalid parameters
-   `401` Unauthorized - API key missing or invalid
-   `429` The OAuth connection’s request limit is reached. Nothing was executed: repeat the same request after Retry-After seconds.

## Errors

Errors share one shape: `statusCode`, `message`, `code` and `error`, with the request id in the `X-Request-Id` header.

## All resources

-   [Company](https://api.fiz.co/docs/api/company) ([Markdown](https://api.fiz.co/docs/api/company.md))
-   [Customers](https://api.fiz.co/docs/api/customers) ([Markdown](https://api.fiz.co/docs/api/customers.md))
-   [Items](https://api.fiz.co/docs/api/items) ([Markdown](https://api.fiz.co/docs/api/items.md))
-   [Invoices](https://api.fiz.co/docs/api/invoices) ([Markdown](https://api.fiz.co/docs/api/invoices.md))
-   [Recurring invoices](https://api.fiz.co/docs/api/recurring-invoices) ([Markdown](https://api.fiz.co/docs/api/recurring-invoices.md))
-   [Pro formas](https://api.fiz.co/docs/api/pro-formas) ([Markdown](https://api.fiz.co/docs/api/pro-formas.md))
-   [Transport documents](https://api.fiz.co/docs/api/transport-documents) ([Markdown](https://api.fiz.co/docs/api/transport-documents.md))
-   [Series](https://api.fiz.co/docs/api/series) ([Markdown](https://api.fiz.co/docs/api/series.md))
-   [PDF templates](https://api.fiz.co/docs/api/pdf-templates) ([Markdown](https://api.fiz.co/docs/api/pdf-templates.md))
-   [Exports](https://api.fiz.co/docs/api/exports) ([Markdown](https://api.fiz.co/docs/api/exports.md))
-   [Expenses](https://api.fiz.co/docs/api/expenses) ([Markdown](https://api.fiz.co/docs/api/expenses.md))
-   [VAT](https://api.fiz.co/docs/api/vat) ([Markdown](https://api.fiz.co/docs/api/vat.md))
-   [Bank](https://api.fiz.co/docs/api/bank) ([Markdown](https://api.fiz.co/docs/api/bank.md))
