> For the complete documentation index, see [llms.txt](https://ledgera.gitbook.io/api/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ledgera.gitbook.io/api/operation/authorization-confirmation.md).

# Authorization / Confirmation

{% hint style="info" %} <mark style="color:blue;">Information: authorization is a transaction that requires a second call to be considered complete - be it a confirmation or a reversal.</mark>
{% endhint %}

## Creating an authorization <a href="#creating-an-authorization" id="creating-an-authorization"></a>

To perform a transaction that will follow the accounting movements mapped in the Authorization Rules, the POST /execution method must be used.

The user must inform the parameters:

| Parameter           | Description                                                                                                                                                             |
| ------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *transaction\_type* | The type of the transaction, as mapped in the Execution Rules                                                                                                           |
| *currency*          | The currency of the transaction                                                                                                                                         |
| *amount*            | The main amount of the transaction                                                                                                                                      |
| *param\_account\_1* | The ID of the account used as parameter 1 of the transaction. Not mandatory                                                                                             |
| *param\_account\_2* | The ID of the account used as parameter 2 of the transaction. Not mandatory                                                                                             |
| *settled\_at*       | The date for the transaction to be accounted in further reports. If this parameter is not informed, the system will consider the date when the transaction was created. |
| *external\_id*      | User value set for later conciliation                                                                                                                                   |

Example of authorization creation:

```json
POST /authorization

{
  "transaction_type": "pix_out",
  "currency": "brl",
  "amount": 10000,
  "param_account_1": "2874d9c5-e919-8715-b3eb-4ee3440a2fe3",
  "param_account_2": "bb2b0e40-2308-5330-bb6a-6de434493f0e",
  "settled_at": "2023-06-01",
  "external_id": "our id 1234",
  "custom_entries": [
    {
      "entry_type": "pix_out_fee",
      "decimals": 2,
      "amount_type": "value",
      "amount": 250
    }
  ],
  "metadata": {
    "key": "value"  
  }
}
```

Response Example:

```json
{
  "id": "96296a5c-0cf4-4025-dbc4-1a53f0a3afc6"
}
```

## Confirming an authorization <a href="#confirming-an-authorization" id="confirming-an-authorization"></a>

To confirm an authorization, the POST /authorization/{id}/confirm method must be used. The settled\_at parameter can be optionally informed.

A transaction ID is generated for the confirmation and it is related to the previous authorization ID in the parent\_id data of the transaction.

Example of an authorization confirmation:

```json
POST /authorization/96296a5c-0cf4-4025-dbc4-1a53f0a3afc6/confirm

{
  "settled_at": "2023-06-01"
}
```

Response Example:

```json
{
  "id": "67124d76-c7c5-4604-a50b-0345d95af229"
}
```

## Reverting an authorization <a href="#reverting-an-authorization" id="reverting-an-authorization"></a>

To revert an authorization, the POST /authorization/{id}/revert method must be used. The settled\_at parameter can be optionally informed.

A transaction ID is generated for the reversal and it is related to the previous authorization ID in the parent\_id data of the transaction.

Example of an authorization confirmation:

```json
POST /authorization/96296a5c-0cf4-4025-dbc4-1a53f0a3afc6/revert

{
  "settled_at": "2023-06-01"
}
```

Response Example:

```json
{
  "id": "bb12419f-9947-49a1-8f3e-1b6af04c9ef1"
}
```

***

## Retrieving unconfirmed authorizations <a href="#retrieving-unconfirmed-authorizations" id="retrieving-unconfirmed-authorizations"></a>

To query all authorizations that have not yet been confirmed (or reversed), the GET /authorization/unconfirmed method must be used.

Response Example:

```json
{
  "data": [
    {
      "transaction_id": "659388b0-0597-41c5-9ace-bc499018f8f3",
      "transaction_type": "pix_out",
      "created_at": "2023-06-05T11:26:17.325Z"
    }  
  ]
}
```

<br>
