# Set up your ledger and post a journal entry

Loans post to a ledger. Before they do, the ledger needs accounts, and the organisation-level financial activities need to know which account they post to. You create the accounts, map the activities, then post a manual journal entry.

## Before you start

- A user: With accounting permissions on the tenant. (https://developer.lokta.ai/api/roles-permissions/)
- An office id: A journal entry is posted for an office. The examples use `officeId` 1.
- Your chart of accounts: The names, codes and types of the accounts you want to create.

## Set your environment

Every request authenticates with HTTP Basic and names its tenant in a header. Set these once and the commands below work as written.

```bash
export LOKTA_API="https://default.lokta.tech"
export LOKTA_USER="your-username"
export LOKTA_PASS="your-password"
```

## 1. Read the account template

The template returns the allowed values for the fields a ledger account needs. The type and usage of an account are integer codes, and this is where you find which code means what on your tenant.

[GET /v1/glaccounts/template](https://developer.lokta.ai/api/general-ledger/retrieve-new-account-details.md)

```bash
curl -X GET "$LOKTA_API/lokta-lms/api/v1/glaccounts/template" \
  -u "$LOKTA_USER:$LOKTA_PASS" \
  -H "Tenant-Identifier: default"
```

## 2. Create a ledger account

These fields are mandatory. To build a hierarchical chart of accounts, send a parentId that points at another account.

- `name`: The account name.
- `glCode`: The account code, as a string.
- `type`: The account type, as the integer code from the template.
- `usage`: How the account is used, as the integer code from the template.
- `manualEntriesAllowed`: True if people may post to the account by hand.
- `parentId`: Optional. The account this one sits under.

The type and usage codes above are examples. Use the codes the template returns.

[POST /v1/glaccounts](https://developer.lokta.ai/api/general-ledger/create-glaccount.md)

```bash
curl -X POST "$LOKTA_API/lokta-lms/api/v1/glaccounts" \
  -u "$LOKTA_USER:$LOKTA_PASS" \
  -H "Tenant-Identifier: default" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Loan portfolio",
    "glCode": "10100",
    "type": 1,
    "usage": 1,
    "manualEntriesAllowed": true
  }'
```

Repeat for each account you need, and keep the ids. The mapping and the journal entry below take them as `glAccountId`.

## 3. Map financial activities to accounts

Organisation-level financial activities, such as an asset or liability transfer, post to the account you map them to. Read the template for the activity ids and the accounts on offer.

[GET /v1/financialactivityaccounts/template](https://developer.lokta.ai/api/accounting-setup/retrieve-template.md)

```bash
curl -X GET "$LOKTA_API/lokta-lms/api/v1/financialactivityaccounts/template" \
  -u "$LOKTA_USER:$LOKTA_PASS" \
  -H "Tenant-Identifier: default"
```

## 4. Create the mapping

Send the financial activity and the ledger account it should post to.

[POST /v1/financialactivityaccounts](https://developer.lokta.ai/api/accounting-setup/create-glaccount-mapping-financial-activity-account.md)

```bash
curl -X POST "$LOKTA_API/lokta-lms/api/v1/financialactivityaccounts" \
  -u "$LOKTA_USER:$LOKTA_PASS" \
  -H "Tenant-Identifier: default" \
  -H "Content-Type: application/json" \
  -d '{
    "financialActivityId": 100,
    "glAccountId": 1
  }'
```

The ids above are examples. Use the ones from the template and from your own accounts.

## 5. Post a journal entry

A simple entry has at least one debit and one credit, and the two sides must add up to the same amount. A compound entry can have several of each.

The office and the transaction date are mandatory. Each debit and credit line carries a glAccountId, an amount and a comment.

[POST /v1/journalentries](https://developer.lokta.ai/api/journal-entries/create-gljournal-entry.md)

```bash
curl -X POST "$LOKTA_API/lokta-lms/api/v1/journalentries" \
  -u "$LOKTA_USER:$LOKTA_PASS" \
  -H "Tenant-Identifier: default" \
  -H "Content-Type: application/json" \
  -d '{
    "officeId": 1,
    "transactionDate": "01 September 2026",
    "comments": "Opening funding",
    "debits": [
      {
        "glAccountId": 1,
        "amount": 100000,
        "comments": "Funds in"
      }
    ],
    "credits": [
      {
        "glAccountId": 2,
        "amount": 100000,
        "comments": "Funds source"
      }
    ],
    "dateFormat": "dd MMMM yyyy",
    "locale": "en"
  }'
```

## 6. Read the entries back

List entries for an office or an account, narrowed by date, then open one to see its lines.

[GET /v1/journalentries](https://developer.lokta.ai/api/journal-entries/retrieve-all-journal-entries.md)

```bash
curl -X GET "$LOKTA_API/lokta-lms/api/v1/journalentries" \
  -u "$LOKTA_USER:$LOKTA_PASS" \
  -H "Tenant-Identifier: default"
```

## Where to go next

- [Close a period](https://developer.lokta.ai/guides/close-the-period/)
- [General Ledger reference](https://developer.lokta.ai/api/general-ledger/)
