# Save the opening balances

`POST https://api.fiscalisto.com/v1/accounting/opening_balances`

Replaces the opening balances: the 1st of the month your books start and each account's debit or credit balance (by its number); both columns add up the same or it answers entry_unbalanced. They're the closing balances of your previous system's trial balance. Without lines, it deletes them. Nothing before that date counts.

## Parameters

| Name | In | Required | Description |
| --- | --- | --- | --- |
| `Idempotency-Key` | header |  | Optional (the SDKs send it on their own). If the response is lost, repeat the request with the same value within 24 hours: it answers the same, with idempotent-replayed: true, and doesn't do it twice (it doesn't create, send emails or charge). |

## Body

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `issuer` | string |  | The issuer (iss_…). By default, your only issuer. |
| `date` | string | yes | When your books start (the 1st of a month): what's before isn't counted. |
| `lines` | array of object | yes | Each account's balance, debit or credit; both columns add up the same. Without lines, it deletes the opening balances. (up to 5000) |
| `lines[].account` | string | yes | The account's number in your catalog (GET /v1/accounting/accounts), for example 205-06. (up to 100 characters) |
| `lines[].debit` | number |  | Its debit balance. (from 0 to 10000000000000; default 0) |
| `lines[].credit` | number |  | Its credit balance. (from 0 to 10000000000000; default 0) |

Example:

```json
{
  "date": "2026-01-01",
  "lines": [
    {
      "account": "102-01",
      "debit": 150000
    },
    {
      "account": "301-01",
      "credit": 150000
    }
  ]
}
```

## With the TypeScript SDK

```ts
import { Fiscalisto } from "fiscalisto";

// La llave viene de FISCALISTO_API_KEY.
const fiscalisto = new Fiscalisto();

const openingBalances = await fiscalisto.openingBalances.set({
  date: "2026-01-01",
  lines: [
    { account: "102-01", debit: 150000 },
    { account: "301-01", credit: 150000 },
  ],
}, { idempotencyKey: "pedido-A-1042" });
```

## With the Python SDK

```python
from fiscalisto import Fiscalisto

# La llave viene de FISCALISTO_API_KEY.
fiscalisto = Fiscalisto()

opening_balances = fiscalisto.opening_balances.set({
    "date": "2026-01-01",
    "lines": [
        {"account": "102-01", "debit": 150000},
        {"account": "301-01", "credit": 150000},
    ],
}, idempotency_key="pedido-A-1042")
```

## With the PHP SDK

```php
<?php

use Fiscalisto\Fiscalisto;

// La llave viene de FISCALISTO_API_KEY.
$fiscalisto = new Fiscalisto();

$openingBalances = $fiscalisto->openingBalances->set([
    'date' => '2026-01-01',
    'lines' => [
        [
            'account' => '102-01',
            'debit' => 150000,
        ],
        [
            'account' => '301-01',
            'credit' => 150000,
        ],
    ],
], ['idempotency_key' => 'pedido-A-1042']);
```

## With the .NET SDK

```csharp
using Fiscalisto;

// La llave viene de FISCALISTO_API_KEY.
var fiscalisto = new FiscalistoClient();

var openingBalances = await fiscalisto.OpeningBalances.SetAsync(new SetOpeningBalancesParams
{
    Date = "2026-01-01",
    Lines = new()
    {
        new() { Account = "102-01", Debit = 150000 },
        new() { Account = "301-01", Credit = 150000 },
    },
}, new RequestOptions { IdempotencyKey = "pedido-A-1042" });
```

## With the Go SDK

```go
package main

import (
	"context"
	"fmt"
	"log"

	fiscalisto "fiscalisto.com/go"
)

func main() {
	// La llave viene de FISCALISTO_API_KEY.
	client, err := fiscalisto.NewClient("")
	if err != nil {
		log.Fatal(err)
	}
	ctx := context.Background()

	openingBalances, err := client.OpeningBalances.Set(ctx, &fiscalisto.SetOpeningBalancesParams{
		Date: "2026-01-01",
		Lines: []fiscalisto.SetOpeningBalancesParamsLine{
			{Account: "102-01", Debit: fiscalisto.Float64(150000)},
			{Account: "301-01", Credit: fiscalisto.Float64(150000)},
		},
	}, fiscalisto.WithIdempotencyKey("pedido-A-1042"))
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%+v\n", *openingBalances)
}
```

## With the Java SDK

```java
import com.fiscalisto.FiscalistoClient;
import com.fiscalisto.RequestOptions;
import com.fiscalisto.model.SetOpeningBalancesParams;
import com.fiscalisto.model.SetOpeningBalancesParamsLine;
import java.util.List;

// La llave viene de FISCALISTO_API_KEY.
var fiscalisto = new FiscalistoClient();

var openingBalances = fiscalisto.openingBalances().set(new SetOpeningBalancesParams()
        .setDate("2026-01-01")
        .setLines(List.of(
                new SetOpeningBalancesParamsLine()
                        .setAccount("102-01")
                        .setDebit(150000),
                new SetOpeningBalancesParamsLine()
                        .setAccount("301-01")
                        .setCredit(150000)
        )), RequestOptions.idempotencyKey("pedido-A-1042"));
System.out.println(openingBalances);
```

## Response 200

OK.

A `OpeningBalances` object:

| Field | Type | Always present | Description |
| --- | --- | --- | --- |
| `object` | `"opening_balances"` | yes | What kind of object it is («invoice», «customer»…). |
| `livemode` | boolean | yes | true in production (fk_live_ keys), false in test mode (fk_test_). Test objects aren't valid before the SAT. |
| `issuer` | string | yes | The issuer. |
| `date` | string or null | yes | The day its books start, or null if it has no opening balances. |
| `lines` | array of object | yes | Each account's balance: debit or credit. |
| `lines[].account` | string | yes | The account number. |
| `lines[].account_name` | string | yes | The account name. |
| `lines[].debit` | number | yes | The debit, in pesos. |
| `lines[].credit` | number | yes | The credit, in pesos. |

```json
{
  "object": "opening_balances",
  "livemode": false,
  "issuer": "iss_OufpKqnrvx9p",
  "date": "2026-01-01",
  "lines": [
    {
      "account": "102-01",
      "account_name": "Bancos nacionales",
      "debit": 150000,
      "credit": 0
    },
    {
      "account": "301-01",
      "account_name": "Capital fijo",
      "debit": 0,
      "credit": 150000
    }
  ]
}
```

## Errors

- `account_missing` (400): That account isn't in the issuer's chart of accounts: see it with GET /v1/accounting/accounts or add it with POST /v1/accounting/accounts.
- `entry_unbalanced` (400): The journal entry doesn't balance or a line is wrong: debits must add up to the same as credits, and each line has a debit or a credit, not both. The message gives the sums.
- `feature_not_in_plan` (403): Live, this part of the API (inventario, portal de proveedores, pedidos, comprobación de gastos) follows the empresa's plan, as in the app: it comes with Operaciones (added to any paid plan; included in Corporativo). The books (the /v1/accounting routes except DIOT, cross checks, IVA refunds and fixed assets) come with Contabilidad (added to Independiente, Emprendedor or Negocio; included in Despacho and Corporativo): without it, changing the books answers this error, and reading them works only up to the last month it had it. Add either in Ajustes › Plan y pagos; test mode has everything.
- `issuer_archived` (400): The issuer is archived and no longer stamps. Its documents can still be read and canceled.
- `issuer_linked_empresa` (403): That issuer is an empresa of the app connected to your account: through the API it only offers its Portal de proveedores (/v1/portal_suppliers and /v1/supplier_invoices) and, once someone who may pay suppliers and change Configurar pagos turned them on, its supplier payouts (/v1/payouts and /v1/payroll_payouts). It also stops when whoever connected it (or turned its payouts on) no longer has that permission in the empresa: message_es says which. Do everything else in the app.
- `issuer_missing` (404): There is no such issuer in the account (or it belongs to the other mode).
- `issuer_not_allowed` (403): This key can't use that issuer.
- `issuer_required` (400): The account has several issuers and the request doesn't say which: send `issuer` (iss_…).
- `livemode_mismatch` (400): The object belongs to the other mode: an fk_test_ key only sees test data and an fk_live_ key only live data.
- `period_closed` (400): That month of the books is closed: nothing dated in it can be booked, changed or deleted. Reopen it with POST /v1/accounting/closed_period to correct it.

Plus those of any call (key, fields, limits): https://fiscalisto.com/en/docs/api/errores.md.
