# Script API reference

The supported script surface contains two authenticated POST operations. API base: `https://api.pijon.fyi/api/v1`.

Download the [OpenAPI specification](/docs/openapi.json). It is extracted with Scribe and checked against the request validators and response contract. Account APIs are intentionally outside this script-key specification; use the app for setup, approval, History, and usage.

## POST /notifications

Headers: `Authorization: Bearer <application key>`, `Accept: application/json`, `Content-Type: application/json`. Send `Idempotency-Key` for retry safety.

| JSON field | Constraints |
| --- | --- |
| `application_id` | Required application ULID, owned by the key owner and matching its exact scope. |
| `recipient_id` | Required receiving user ULID with active subscription/category approval. |
| `body` | Required string; maximum 10,000 characters. |
| `title` | Optional/nullable string; maximum 120 characters; defaults to application name. |
| `body_format` | `plain` (default) or `markdown`. |
| `category` | Active category key belonging to this application. Default `general`; lowercase letters/digits/underscores, starting with a letter, at most 64 characters. No global enum. |
| `priority` | `normal` (default), `silent`, `low`, or `high`. |
| `device_ids` | Optional/null for all eligible endpoints; otherwise 1 to 100 device ULIDs. Empty array rejected. |
| `url` | Optional/nullable HTTP/HTTPS URL; maximum 2,048 characters, no embedded credentials. |
| `url_title` | Optional/nullable string; maximum 80 characters. |
| `attachment_id` | Optional/nullable uploaded image ULID belonging to the sender. |
| `external_id` | Optional/nullable string; maximum 128 characters, unique per application while history remains. |
| `event_at` | Optional/nullable date-time for the original event. |
| `ttl` | Integer, 1 to 604,800 seconds; defaults to 86,400. |

Success envelope: `{"data":{"notification":{...},"replayed":false}}`. First acceptance: `202`; identical replay: `200` with `replayed: true`. Notification fields include `id`, source/application/recipient IDs, content, `status`, `endpoint_count`, and timestamps. Delivery rows may be included. Never infer device display from the acceptance response.

## POST /attachments

Use multipart `application_id` (ULID) and `image` (JPEG/PNG/WebP, at most 5 MiB and 4096 by 4096 pixels). Authorization is the same scoped bearer key. `201` returns `data.id`, `mime_type`, `size`, `width`, `height`, and `expires_at`. Use `data.id` as a notification's `attachment_id`. See [image workflow](/docs/sending).

## Errors

Validation: `422` with `message` and field `errors`. Domain errors carry `reason` and `message`; authentication/throttling errors may only carry `message`. Check HTTP status first and tolerate an absent `reason`. `429` includes `Retry-After`. Foreign private resources can return `404`.

Common reasons: `application_scope_required`, `application_paused`, `recipient_not_authorized`, `invalid_category`, `invalid_destinations`, `invalid_attachment`, `idempotency_conflict`, `daily_quota_exceeded`, `monthly_quota_exceeded`, `queue_full`, `attachment_storage_full`. Follow [Troubleshooting](/docs/troubleshooting) and [retry guidance](/docs/reliability).
