> ## Documentation Index
> Fetch the complete documentation index at: https://docs.wede.pt/llms.txt
> Use this file to discover all available pages before exploring further.

# Offline policy

> Write your limits for operations without network, choose the version in use and read the decisions wede checked.

```text theme={null}
GET  /v1/policies/current
GET  /v1/policies
GET  /v1/policies/{id}
POST /v1/policies
POST /v1/policies/{id}/activate
POST /v1/policies/{id}/archive
GET  /v1/policies/decisions
```

See [Offline policy](https://docs.wede.pt/concepts/offline-policy.md) for what the rules mean, what devices do with them and what wede checks.

## Authentication

An API key of your organisation, or a session of a user of your organisation. Reading needs `policies:view` and changing needs `policies:manage`, which administrators, technical staff and API keys have. `GET /v1/policies/current` also accepts any credential with `sync:write`, so every device that syncs can read the policy in use. The policy is the same for production and the sandbox.

## The policy in use

`GET /v1/policies/current`

The document devices keep and apply, with its `sha256`. Both are `null` when no policy is in use.

```json theme={null}
{
  "policy": {
    "format": "wede-policy/1",
    "tenant_id": "5b0e6a52-2f7c-4d1b-9a8e-3c4d5e6f7a8b",
    "version": 3,
    "rules": [
      {
        "operation_type": "payment_offline",
        "currency": "EUR",
        "max_amount_minor": 5000,
        "cumulative": { "max_amount_minor": 20000, "max_count": 10 }
      }
    ]
  },
  "sha256": "85d5ca0dc00b78706b46cdd7df9d15598347fa132d63164ab5f0d059accb4c4d"
}
```

**sha256** `string`

SHA-256 of `policy` in canonical JSON (object keys sorted at every level, no spaces). Rules come sorted by operation type and currency, so the same rules always give the same document.

## Create a version

`POST /v1/policies`

**name** `string` *required*

1 to 120 characters.

**rules** `array` *required*

1 to 200 rules, one per operation type and currency: `operation_type` (an operation type of your catalog), `currency` (3 letters), `max_amount_minor` (whole number, minor units) and, optionally, `cumulative` with `max_amount_minor`, `max_count` or both. Any other field is refused.

**activate** `boolean`

`true` makes this version the one in use at once. Default `false`.

```bash theme={null}
curl -X POST https://api.wede.pt/v1/policies \
  -H "x-wede-api-key: wede_live_YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Payments without network",
    "activate": true,
    "rules": [
      { "operation_type": "payment_offline", "currency": "EUR", "max_amount_minor": 5000,
        "cumulative": { "max_amount_minor": 20000, "max_count": 10 } }
    ]
  }'
```

`201 Created`

```json theme={null}
{
  "id": "c6cc0b27-5f55-47c3-ae09-468e5dbc2e9c",
  "version": 3,
  "name": "Payments without network",
  "rules": [{ "operation_type": "payment_offline", "currency": "EUR", "max_amount_minor": 5000, "cumulative": { "max_amount_minor": 20000, "max_count": 10 } }],
  "sha256": "85d5ca0dc00b78706b46cdd7df9d15598347fa132d63164ab5f0d059accb4c4d",
  "is_active": true,
  "archived_at": null,
  "activated_at": "2026-10-25T21:53:51.940Z",
  "created_at": "2026-10-25T21:53:51.940Z"
}
```

A version never changes once saved: to change a rule, create the next version.

## Choose the version in use

`POST /v1/policies/{id}/activate` makes a version the one in use; the previous one is kept. Devices receive it at their next sync. An archived version cannot be used again (`409 archived`).

`POST /v1/policies/{id}/archive` stops a version and takes it out of the list. Archiving the version in use leaves no policy in use: devices stop applying limits once they sync.

Both return the version.

## List and read

`GET /v1/policies` returns the versions of your organisation in `data`, the newest first; add `archived=true` to include the archived ones. `GET /v1/policies/{id}` returns one version.

## Decisions

`GET /v1/policies/decisions`

The decisions wede checked, the newest first, with a count per result in `summary`.

**mismatch** `boolean`

`true` returns only the decisions that did not match.

**environment** `string`

`production` (default) or `sandbox`, with a session. With an API key, the environment of the key.

**limit** `integer`

1 to 500. Default 100.

```json theme={null}
{
  "environment": "production",
  "summary": { "ok": 14, "over_max_amount": 1, "declined_but_sent": 1 },
  "data": [
    {
      "ledger_id": "439e46c0-f70d-4107-9c56-5d1fcb36a5e0",
      "device_key": "POS-0042",
      "operation_code": "payment_offline",
      "result": "allowed",
      "rule": null,
      "policy_version": 3,
      "amount_minor": 6000,
      "currency": "EUR",
      "cumulative_amount_minor": 0,
      "cumulative_count": 0,
      "captured_at": "2026-10-25T19:28:10.995Z",
      "check_result": "over_max_amount",
      "checked_at": "2026-10-25T20:26:11.077Z"
    }
  ]
}
```

**data\[].result** `string`

What the device decided: `allowed`, `declined` (with `rule`) or `no_policy`.

**data\[].cumulative\_amount\_minor** `integer`

What the device had accepted for this type and currency since its last sync, before this operation. `cumulative_count` is the number.

**data\[].check\_result** `string`

`ok`, or the reason it did not match: `over_max_amount`, `over_cumulative_amount`, `over_cumulative_count`, `declined_but_sent`, `unknown_version`, `policy_altered`, `cumulative_missing`, `cumulative_chain` or `decision_invalid`. See [What wede checks](https://docs.wede.pt/concepts/offline-policy.md#what-wede-checks).

An operation is never refused or delayed because of its decision: it is kept like any other.

## Errors

| Status | Code | When |
| - | - | - |
| 401 | `unauthorized` | Credential missing, malformed, revoked or expired |
| 403 | `forbidden` | A role without the permission, or a user outside an organisation |
| 404 | `not_found` | The version does not exist in your organisation |
| 409 | `archived` | Using an archived version |
| 422 | `invalid_payload` | A missing or too long name, or `activate` not a boolean |
| 422 | `invalid_policy` | Rules that are not valid (`details` says which and why), for example a duplicate type and currency or a field that is not allowed |
| 422 | `unknown_operation_type` | An operation type that is not active in your catalog (`unknown` lists them; `inactive` the ones that exist but are turned off) |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.