# Welcome to the iCount API

The iCount API gives you programmatic access to nearly every feature of the system — clients, documents, payments, expenses, inventory, reports, and more. It is actively maintained and continuously expanded.

All endpoints accept `POST` requests with a JSON-encoded payload and return JSON responses. The base URL is:

```
https://api.icount.co.il/api/v3.php/
```

Before sending any request, you must authenticate. The API supports **three authentication methods**, each suited to a different use case.

---

## Method 1 — API Token (Recommended)

Generate a long-lived API token from the <a href="https://app.icount.co.il/admin/settings_automation.php#tabs-api-tokens" target="_blank" rel="noopener">API Tokens settings page</a> and send it in the `Authorization` header as a Bearer token. **This is the recommended method for all integrations.**

Each token is linked to a specific user account and inherits **exactly the same privileges and permissions** as that user. A token can never do more than the user it belongs to — if you need restricted access, create a dedicated user with limited permissions and generate the token under that user.

<div class="method-info">
  <div class="method-info-card method-info-when">
    <div class="method-info-title">When to use it</div>
    <ul>
      <li>Server-to-server integrations.</li>
      <li>Background jobs, cron tasks, webhooks, mobile apps.</li>
      <li>Any production workload that needs a stable, revocable credential.</li>
    </ul>
  </div>
  <div class="method-info-card method-info-pros">
    <div class="method-info-title">Benefits</div>
    <ul>
      <li>No expiration — works until you explicitly revoke it.</li>
      <li>Username and password are never transmitted.</li>
      <li>Revocable and rotatable independently of user credentials.</li>
      <li>Clean separation between auth and request payload.</li>
      <li>Works with standard Bearer-token HTTP tooling.</li>
    </ul>
  </div>
  <div class="method-info-card method-info-cons">
    <div class="method-info-title">Drawbacks</div>
    <ul>
      <li>Tokens must be stored securely (treat them like passwords).</li>
      <li>If leaked, they grant access until revoked.</li>
    </ul>
  </div>
</div>

**Example**

```bash
curl -X POST 'https://api.icount.co.il/api/v3.php/client/get_list' \
  -H 'Authorization: Bearer XXXXXXXX-XXXXXXXX-XXXXXXXX-XXXXXXXX' \
  -H 'Content-Type: application/json' \
  -d '{}'
```

---

## Method 2 — Session ID (`sid`)

Authenticate once via the [`auth/login`](#/module/auth/login) endpoint, receive a session ID, and reuse it for subsequent requests.

A session remains valid for **20 minutes** from the last request — every new request resets the timer. Once expired, you must log in again.

<div class="method-info">
  <div class="method-info-card method-info-when">
    <div class="method-info-title">When to use it</div>
    <ul>
      <li>Interactive apps where a user is actively working (dashboards, internal tools).</li>
      <li>Workloads that make many requests in a short time window.</li>
    </ul>
  </div>
  <div class="method-info-card method-info-pros">
    <div class="method-info-title">Benefits</div>
    <ul>
      <li>Credentials are sent only once, reducing exposure.</li>
      <li>Faster than sending credentials on every request.</li>
      <li>Sliding expiration keeps active sessions alive automatically.</li>
    </ul>
  </div>
  <div class="method-info-card method-info-cons">
    <div class="method-info-title">Drawbacks</div>
    <ul>
      <li>Expires after 20 minutes of inactivity — not ideal for long background jobs unless you handle re-login.</li>
      <li>Requires storing and refreshing the <code>sid</code>.</li>
    </ul>
  </div>
</div>

**Step 1 — Log in:**

```bash
curl -X POST 'https://api.icount.co.il/api/v3.php/auth/login' \
  -H 'Content-Type: application/json' \
  -d '{
    "cid": "your-company-id",
    "user": "your-username",
    "pass": "your-password"
  }'
```

The response contains a `sid` field.

**Step 2 — Use the `sid` on subsequent requests:**

```bash
curl -X POST 'https://api.icount.co.il/api/v3.php/client/get_list' \
  -H 'Content-Type: application/json' \
  -d '{
    "sid": "the-session-id-you-received"
  }'
```

---

## Method 3 — Credentials on Every Request

Send your `cid` (company ID), `user`, and `pass` as part of the request body for every call.

<div class="method-info">
  <div class="method-info-card method-info-when">
    <div class="method-info-title">When to use it</div>
    <ul>
      <li>Quick one-off scripts or testing.</li>
      <li>Environments where storing a token or session is not practical.</li>
    </ul>
  </div>
  <div class="method-info-card method-info-pros">
    <div class="method-info-title">Benefits</div>
    <ul>
      <li>Simplest to get started — no extra setup, no token management.</li>
      <li>Stateless: each request is fully self-contained.</li>
    </ul>
  </div>
  <div class="method-info-card method-info-cons">
    <div class="method-info-title">Drawbacks</div>
    <ul>
      <li>Credentials travel with every request, increasing exposure risk.</li>
      <li>Slower: the server re-authenticates on each call.</li>
    </ul>
  </div>
</div>

**Example**

```bash
curl -X POST 'https://api.icount.co.il/api/v3.php/client/get_list' \
  -H 'Content-Type: application/json' \
  -d '{
    "cid": "your-company-id",
    "user": "your-username",
    "pass": "your-password"
  }'
```

---

## Quick Comparison

<div class="auth-compare">
  <div class="auth-card auth-card-recommended">
    <div class="auth-card-header">
      <span class="auth-card-title">API Token</span>
      <span class="auth-card-badge">Recommended</span>
    </div>
    <ul>
      <li><span class="auth-label">Best for</span><span>Production integrations</span></li>
      <li><span class="auth-label">Setup</span><span>Generate once in the UI</span></li>
      <li><span class="auth-label">Expiration</span><span>None (until revoked)</span></li>
      <li><span class="auth-label">Security</span><span class="auth-sec-best">Best — credentials never sent</span></li>
    </ul>
  </div>
  <div class="auth-card">
    <div class="auth-card-header">
      <span class="auth-card-title">Session ID</span>
    </div>
    <ul>
      <li><span class="auth-label">Best for</span><span>Interactive apps</span></li>
      <li><span class="auth-label">Setup</span><span>One login call</span></li>
      <li><span class="auth-label">Expiration</span><span>20 min sliding</span></li>
      <li><span class="auth-label">Security</span><span class="auth-sec-good">Better — credentials sent once</span></li>
    </ul>
  </div>
  <div class="auth-card">
    <div class="auth-card-header">
      <span class="auth-card-title">Credentials</span>
    </div>
    <ul>
      <li><span class="auth-label">Best for</span><span>Quick scripts, testing</span></li>
      <li><span class="auth-label">Setup</span><span>None</span></li>
      <li><span class="auth-label">Expiration</span><span>N/A</span></li>
      <li><span class="auth-label">Security</span><span class="auth-sec-low">Lowest — sent every call</span></li>
    </ul>
  </div>
</div>

---

Once you've chosen an authentication method, send a `POST` request to the desired endpoint with your JSON payload. Browse the modules in the sidebar to explore the full list of available endpoints.
