# Approval

> Approvals: the calls NoClick holds for your account's owner's yes, read and answered from your own code.

When an agent, a connected app, a key used through MCP or an app's own code makes a purchase, a deletion that can't
be undone, a call your policy holds or one that raises a spending limit, NoClick holds the exact call and sends your
account's owner a link to approve it. Your code may answer it too, with one of your account's secret keys that
names the `approvals:answer` scope (a key with every scope, `*`, holds it only when it's named too):

```python
for approval in noclick.Approval.list(status="pending"):
    if approval.price and approval.price["amount_usd"] <= 20:
        approval.approve(note="Under $20: fine.")
```

A key never answers a call made with it (by its own code, through MCP, or by an agent or app acting as it), never
approves one whose terms a person accepts (it may decline it), and approves only what it could make itself: the
scopes the call needs (never a call only the owner and their NoClick assistant make), and a price that fits the key's
own monthly cap beside what it spent and approved this month (what it approves also counts against what it may
still spend itself). NoClick then runs an approved call itself, once, exactly as it was held, with no scope the
answering key lacks. While your account holds a key that would approve it, a call whose link reaches no person is
still held, with an empty `sent_to`, for your code (or the owner, signed in) to answer.

## Approval

```typescript
class Approval
```

A call held for your account's owner's yes, as they see it on its page.

| Attribute | Type | Description |
| --- | --- | --- |
| `id` | `string` |  |
| `status` | `ApprovalStatus` | Where it stands (`used`: approved, and run). |
| `action` | `string | null` | What the call does, in a person's words. |
| `price` | `JsonObject | null` | A purchase's price (`amount_usd`, `recurrence`, `terms`, `renewal`); null for anything else. |
| `reason` | `string | null` | Why it waits for a person. |
| `operation` | `string` | The API operation it calls, by name (`phone_numbers_create`). |
| `method` | `string | null` |  |
| `path` | `string | null` |  |
| `arguments` | `JsonObject` | Its arguments as the page shows them, secrets masked. |
| `connection` | `JsonObject` | Who made it: `kind` (`assistant`, `agent`, `connected_app` or `key`) and `name`. |
| `userId` | `string | null` | The user it acts for (null for your account). |
| `operationId` | `string` | The held call's operation: `Operation.fromId(...).wait()` gives what it returned once approved, or throws once declined or expired. |
| `impact` | `JsonObject | null` | What a deletion takes with it; null for anything else. |
| `consent` | `JsonObject[]` | Terms a person accepts by approving it (each `terms`, `title`, `url`): only the owner approves such a call. |
| `sentTo` | `string[]` | Where NoClick sent the owner its link: `whatsapp`, `imessage`, `email`, or `web` (a card in the chat); empty when it reached nobody and waits for your code. |
| `createdAt` | `Date | null` |  |
| `expiresAt` | `Date | null` | When it lapses unanswered (a day after it was held). |
| `decidedAt` | `Date | null` |  |
| `decidedBy` | `"owner" | "code" | null` | Who decided: `owner` (signed in, or from NoClick's link) or `code`; null while pending. |
| `decidedByKey` | `{ key_id: string; key_name: string | null } | null` | The key whose code decided (`key_id`, `key_name`); null otherwise. |
| `note` | `string | null` | What whoever decided wrote with it. |

Types:

```typescript
type ApprovalStatus = "pending" | "approved" | "declined" | "expired" | "used" | "canceled";

type JsonObject = { [key: string]: unknown };
```

### Approval.fromId

```typescript
static fromId(
  approvalId: string,
  options?: Pick<CallOptions, "client">,
): Approval
```

A lazy reference to an approval by its id (an `ApprovalRequired`'s `approvalId`).

Parameters:

- `approvalId` (`string`, required)
- `options.client` (`NoClick`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.

Returns: The approval; it loads the first time it's used.

### Approval.list

```typescript
static list(options?: ApprovalListOptions): Promise<Approval[]>
```

Calls held for your account's owner's yes, newest first: the first 20, or the first `limit` (at most 100).
Acting for a user, that user's alone.

Parameters:

- `options.status` (`ApprovalStatus`): One status; omitted, every one.
- `options.limit` (`number`): The first this many (20 unless you say, at most 100).
- `options.user` (`UserOption`, default: the current user): `undefined` = the ambient user (`asUser`), `null` = the account itself.
- `options.client` (`NoClick`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.
- `options.userFilter` (`UserFilter`): Which users the read covers (`user_id` query), instead of acting as one (`user`).

Returns: Each approval as its page shows it.

Types:

```typescript
type ApprovalStatus = "pending" | "approved" | "declined" | "expired" | "used" | "canceled";

/**
 * Which users a read covers: `ALL_USERS`, `NO_USER`, a `User` or your id for one. Sent as the
 * `user_id` query parameter, never as the `NoClick-User` header, so it filters without acting as the user.
 */
type UserFilter = typeof ALL_USERS | typeof NO_USER | UserRef;

/** A `User` or your own id for the user. */
type UserRef = string | UserLike;

/** Anything that can name a user lazily (a `User`). */
interface UserLike {
  _userId(): Promise<string>;
}

/** `undefined` = the ambient user (from `asUser`), `null` = the account itself. */
type UserOption = UserRef | null | undefined;
```

### Approval.approve

```typescript
approve(options?: { note?: string }): Promise<this>
```

Approve it from your own code, with one of your account's secret keys that names the `approvals:answer` scope;
NoClick then runs the call itself, once, exactly as it was held. Throws `PermissionDenied` for the key the call
was made with, a call whose terms a person accepts, one needing a scope the key lacks or only the owner makes, a
key acting for a user, and a key without the scope; `SpendCapExceeded` when its price, beside what the key spent
and approved this month, is past the key's own monthly cap.

Parameters:

- `options.note` (`string`)

Returns: This approval, answered: `status` is `approved`, then `used` once the call ran;
`decided_by` is `code`.

### Approval.decline

```typescript
decline(options?: { note?: string }): Promise<this>
```

Decline it from your own code, as `approve` answers it: the call never runs, and whoever made it is told why,
with your `note`. A call whose terms a person accepts may be declined from code too.

Parameters:

- `options.note` (`string`)

Returns: This approval, answered: `status` is `declined`.
