stashly

API

Everything the web page does goes through this API, so scripts can do it too. See the README for the short version.

API

Method Path Purpose
POST /api/stashes {slug, password?, ttl} creates a stash. {slug, password, ttl, vault} makes a Vault stash (end-to-end encrypted, see Features): password is a 43-character key the page derives from the passphrase, vault is {v:1, kdf:{alg:'PBKDF2-SHA256', iter, salt}, wrapped, recovery:{salt, wrapped, authKey}} (made by src/views/vault.js). Titles and texts are then ciphertext (v1.…) the server cannot read; a locked Vault answers 401 with vault: {kdf, recovery:{salt}}, and a signed-in listing carries the wrapped keys. A Vault note’s tags travel as PUT /items/:id/tags {sealedTags} (one sealed text, or null), never as names. Sharing, import, export, burn, secret and per-note expiry answer 400 for a Vault. Files work, encrypted by the page: POST /files (or the chunked /uploads) takes bytes that start with the 4-byte marker STF1 (else 415) and an X-File-Name that is a sealed text of {name,type,size} (else 400); titles are sealed too (up to 700 characters). The thumbnail (PUT /files/:id/thumb) is sealed the same way. The server serves the bytes as application/octet-stream and cannot open them
POST /api/stashes/:slug/vault/recover A Vault stash’s way back in. {recoveryKey} proves the recovery code (a key made from it) and answers {recovery:{wrapped}}; add {password, vault:{kdf, wrapped}, session} to set a new passphrase’s keys and sign in. Wrong proofs count towards the unlock lockout
GET /api/stashes/suggest a fresh random name
GET /api/stashes/:slug the stash and its items (search (a #tag word in it filters by that tag), tag (a tag name, repeat it for several: a clip must have all of them), startDate, endDate, tz; limit for only 1-200 items and offset (0 or more) to skip that many first, to read a long list in pages; sort (name, added, modified or tags) and dir (asc or desc; each sort has its usual direction) to list them in another order than the saved one, pinned clips staying first (name is what the list shows, modified the last edit or else the time added, tags the clip’s first tag in the alphabet, untagged last; anything else is a 400); total still counts every match and hasMore says whether items remain after this page; a bad limit or offset is a 400). The answer has canManage (the owner, or anyone with full access on a guest’s stash), and every item has tags (a list); the answer has tags: [{ name, count }], every tag in use in the stash, most used first)
POST /api/stashes/:slug/query the same, with those fields in the body so search words stay out of addresses
GET /api/stashes/:slug/items/:id one item in full (a note’s whole text)
POST /api/stashes/:slug/notes {title?, text} (or a plain-text body, which gets an automatic title)
POST /api/stashes/:slug/files raw body, X-File-Name header, optional X-Title header (both URI-encoded)
PUT /api/stashes/:slug/items/:id a note: {title?, text}, or {title} alone to change only the title and keep the text (empty clears it); a file: {title} (empty goes back to the file name). Optional baseEditedAt (the item’s editedAt you started from, null if never edited): if the item was edited since, nothing changes and the answer is 409 { error, conflict: true, item } with the current item in full. Leave it out to skip the check (last write wins)
PUT /api/stashes/:slug/content {content: "all" \| "notes" \| "files"} what the stash takes (full access only)
PUT /api/stashes/:slug/file-types {fileTypes: "safe" \| "no-programs" \| "any"} which files the stash accepts (see File types in the configuration doc; full access only; a new stash starts on safe)
GET /api/stashes/:slug/members the owner only: {members: [{username, displayName, role, addedAt, disabled}], max: 20}, the people the stash is shared with
PUT /api/stashes/:slug/members the owner only: {username, role: "full" \| "view"} shares the stash with an active account by its exact username, or changes their role (201 new, 200 changed; 404 for no such active account, 409 over 20 people, 403 for a stash with no owner). They open it signed in, without the password
DELETE /api/stashes/:slug/members/:username the owner only: removes their access (404 when it was not shared with them)
GET /api/me/users/suggest?q= signed in: up to 5 active accounts whose username starts with q (at least 2 characters), as {users: [{username, displayName}]}; never yourself; limited to 60 requests a minute
PUT /api/stashes/:slug/mcp {access?: true \| false, hideSensitive?: true \| false} whoever manages the stash: whether AI assistants (MCP) may use it (off until turned on) and whether they are kept from its secret and burn-after-reading notes (on by default). Sending one leaves the other as it was. Answers {access, hideSensitive}. The stash’s own response carries mcpEnabled and, for whoever manages it, mcp
PUT /api/stashes/:slug/private {private: true \| false} only the owner (signed in) can: while on, nobody else can open the stash, whatever the password, read-only or drop-box links, or follows say. Every other request answers 404, as if the stash did not exist. Links to single clips keep working. 403 for a stash with no owner. Answers {private}
PUT /api/stashes/:slug/access {mode: "private" | "people" | "password" | "public", password?} only the owner (signed in) can. private and people make the stash private (the list under /members is what makes it “specific people”); password needs a password when the stash has none (an existing one is kept when none is sent; a new one signs everyone else out and cancels share links); public takes the password off, and needs a name of at least MIN_OPEN_NAME_LENGTH characters. Answers {mode, private, hasPassword, shareLinks, sessionEndsAt}
PUT /api/stashes/:slug/display-name {name} only the owner: a display name of up to 60 characters (free text, not unique; empty or null clears it). The stash is still opened by its name. 403 for a guest stash (no owner). A stash’s label is its display name, and clipboardTarget says whether it is the stash the signed-in user’s copied text goes to. Answers {label}
POST /api/stashes/:slug/uploads start a resumable upload: {name, size, title?}. Runs every check a single upload does that needs no bytes (role, stash content kind, size, quotas, name, blocked extension) and answers 201 {id, offset: 0, size, chunkSize} with a Location. See Resumable uploads
GET, HEAD /api/stashes/:slug/uploads/:id where the upload stands: {id, offset, size, chunkSize} (HEAD: the Upload-Offset header only)
PATCH /api/stashes/:slug/uploads/:id send one piece: header Upload-Offset (must equal the current offset, else 409 with the right one), the raw bytes as the body (at most chunkSize: 413). Answers 200 {offset, ...}
POST /api/stashes/:slug/uploads/:id/complete finish (only when offset == size, else 409): checks the content type and the limits again and answers 201 with the item, exactly like a single upload
DELETE /api/stashes/:slug/uploads/:id cancel an unfinished upload and remove what it received (204)
GET /api/stashes/:slug/files/:id the file (?download=1 to force a download)
GET /api/stashes/:slug/files/:id/thumb an image’s thumbnail (full and read-only access; 404 when it has none). Served inline with nosniff, a sandboxing CSP and no-store; an item’s thumbUrl is this address, or null
PUT /api/stashes/:slug/files/:id/thumb attach or replace an image’s thumbnail: the body is the raw JPEG, PNG or WebP bytes (any Content-Type; at most MAX_THUMB_KB: 413; not an image of those types: 415; the item is not an image: 400). Full access any time; a drop-box link only while the image has none and is under 5 minutes old (403 otherwise). Answers the item, and other pages are sent item-updated
GET /api/stashes/:slug/latest newest note as plain text; if it is burn-after-reading, answers 409 and leaves it alone
POST /api/stashes/:slug/latest the same, but a burn-after-reading note is returned and deleted (full access only)
DELETE /api/stashes/:slug/items/:id delete a note or file (full access). Answers { ok: true, undoUntil }: until when it can be restored (an ISO time), or null when it is gone for good (undo off, or a burn-after-reading or secret note)
PUT /api/stashes/:slug/items/:id/tags set a clip’s tags (full access). Body { tags: ["work", "todo"] } replaces them, an empty list clears them. Tags are lowercased and a leading # dropped; a tag has letters, numbers, - and _ only (24 characters at most) and a clip at most 8, else 400. Tagging does not change the clip’s edited time. Answers the clip
GET /api/stashes/:slug/items/:id/share whether the clip has a link (full access): { shared: false }, or { shared: true, createdAt, expiresAt, views, lastViewedAt }. The link itself is never returned again
POST /api/stashes/:slug/items/:id/share make a link to just this clip (full access, any stash). Body { expires } (optional) one of 1h, 1d, 7d (default), 30d, 1y, never; a note’s own expiry caps it. Replaces any earlier link of the clip. Answers 201 { shared, expiresAt, token, path: "/c/<token>", ... } once; a burn-after-reading note is refused (400)
DELETE /api/stashes/:slug/items/:id/share cancel the clip’s link (full access)
GET /api/clips/:token public, no stash or cookie: the clip behind a link as { kind, title, text, fileName, fileType, fileSize, isImage, fileUrl, createdAt, expiresAt }, and nothing about its stash. Counts as one view. A link that does not exist, was cancelled or ran out is always the same 404
GET /api/clips/:token/file public: the bytes of a file clip (?download=1 forces a download, ?view=1 opens a PDF; ranges work), with the same safe headers as a stash’s own file route; 404 for a note
POST /api/stashes/:slug/tags/rename rename a tag on every clip that has it (manage access: the owner, or full access on a guest’s stash; 403 otherwise). Body { from, to }; a clip that already has to just loses from (they merge). Answers { changed, tags } (tags: every tag with its count); 404 when no clip has from, 400 for a bad name or the same name
DELETE /api/stashes/:slug/tags/:name remove a tag from every clip (the clips stay; manage access). Answers { changed, tags }; 404 when no clip has it
POST /api/stashes/:slug/items/move move or copy clips to another stash you own (manage access on this stash; you must be signed in, 403 otherwise, and own the target, 403). Body { ids, to, copy? } with 1 to 500 ids. Move keeps each clip’s id (a file keeps its bytes) and puts them on top of the target in the same order; copy makes new items. Answers { moved, copied, skipped: [{ id, reason }], target } (reason: gone, burn for a burn-after-reading note being copied, kind for notes or files the target does not take). A target limit (items, files, space) refuses it all with 413/507; 404 for an unknown target, 400 for the same stash
POST /api/stashes/:slug/items/bulk many clips at once (full access). Body { action, ids } with action one of delete, restore, pin, unpin, tag, untag, secret and 1 to 500 clip ids (tag and untag also take tag, one tag name). Each clip follows the same rules as the single routes; clips that are not there are skipped and listed under missing. delete answers { deleted, undoable, missing, undoUntil }; restore (the undo of a bulk delete) answers { items, missing, error } and stops early, with error, when a stash limit is reached; pin and unpin answer { items, missing }; tag and untag answer { items, missing, full } (full lists clips that already hold 8 tags); secret makes notes secret and answers { items, missing, skipped } (skipped lists files, which cannot be secret)
POST /api/stashes/:slug/items/:id/restore undo a delete (full access): puts the item back with its id, place and pin; 404 if it is not in the trash or the undo time has passed; 413 or 507 if the stash limits no longer allow it
POST /api/stashes/:slug/extend extend the stash (full access; for a stash with an owner, the owner only: 403 for anyone else, an admin included). No body restarts the timer for the stash’s own length; { ttl } (one of the keys in /api/config ttlOptions, never when allowed) sets a new length counted from now and must end later than it ends now (409 otherwise, 400 for an unknown key or a stash that never expires). Answers { expiresAt, canExtend, extendChoices }; the stash listing carries canExtend and extendChoices (key, label, ms, restart, never) for someone who may
DELETE /api/stashes/:slug delete the stash
GET /api/stashes/:slug/export the whole stash as <slug>.zip (full and read-only access; burn-after-reading notes are left out)
GET /api/me/export sign-in needed. Several of your stashes as one zip, stashly-export-DATE.zip: a folder per stash (what /export holds) and stashly-export.json at the top. ?stash=a&stash=b picks some, none means every stash you can read (your own, shared with you, followed ones you can open). 404 when a picked stash is not yours to read, 413 when too large
POST /api/me/restore sign-in needed. The body is an export zip (Content-Type: application/zip). Answers { id, stashes: [{ key, slug, notes, files, taken, canAdd, suggestion, ... }] } and keeps the zip for 30 minutes. 400 when it is not a backup, 413 when over MAX_TOTAL_MB
POST /api/me/restore/:id { stashes: [{ key, action: "create" \| "add" \| "copy" \| "skip", name }] } (name for a copy). Answers { results: [{ slug, created, notes, files, skipped }] }; a stash that fails has error. 409 when a name is taken, 400 for a bad name or adding to a stash that is not yours. DELETE drops the waiting zip
GET /api/stashes/:slug/export/clipper the notes as a Clipper for Android backup (<slug>-clipper.json): each tag a folder, files and burn notes left out (full and read-only access)
POST /api/stashes/:slug/import {items: [{text, title?, tags?, pinned?, createdAt?}]} (1 to 500 per call) adds notes, keeping their dates; answers {added, skipped: {empty, tooLong, full}, items} (full access)
GET /api/stashes/:slug/events live stream
GET /health, /api/config liveness; expiry options and limits
GET /metrics Prometheus metrics; only when METRICS_TOKEN is set, with Authorization: Bearer <token>
GET /api/admin/backup admin only: the database snapshot and all files as one zip
POST /api/auth/login {username, password} signs a user in (sets stashly_user); one generic 401 for every failure, 429 when locked out. 404 when accounts are off
POST /api/auth/logout signs this browser out
GET /api/me { enabled, user: {id, username, displayName, role, managed} \| null, mcp: {running, path} }, 200 either way ({ enabled: false } when accounts are off)
GET /api/me/mcp-default signed in: {running, enabled}: whether this server runs MCP, and whether the stashes you make from now on start switched on for AI assistants (with secret and burn notes kept from them)
PUT /api/me/mcp-default signed in: {enabled: true | false} turns that on or off. Only stashes made afterwards are affected. Answers like GET
GET /api/me/mcp-tokens signed in: {running, path, max, tokens: [{id, name, last4, createdAt, lastUsedAt}]}, your AI assistant (MCP) tokens (never the token itself)
POST /api/me/mcp-tokens signed in: {name} (required, up to 40 characters, say where it is used) makes a token. 201 {id, name, last4, createdAt, lastUsedAt, token}: the token is shown only now. 409 when the MCP server is not running or you have 10 tokens
DELETE /api/me/mcp-tokens/:id signed in: revokes one of your tokens at once (404 for anyone else’s)
POST /api/me/password {currentPassword, newPassword}: changes your own password, signs out your other sessions
GET /api/me/stashes the stashes you follow with counts and newItems (for a stash you own, mcpAccess says whether AI assistants may use it); a stash whose grant ended shows only slug, role: null, needsPassword: true, addedAt
POST /api/me/clipboard/notes signed in: {text, device?} saves copied text to the stash the user chose (see below). Text identical to the newest note is skipped (200 {saved: false, duplicate: true}); device (for example Chrome Windows) becomes the note’s tag (chrome-windows). 201 {saved: true, slug, label}, 409 {needsStash: true} when no stash is chosen, 403 when the admin turned the feature off, 413 when too long or the stash is full
GET /api/me/clipboard signed in: {enabled, slug, label}: whether the admin allows it, and the stash the user’s copied text goes to (slug is null when none is chosen, it is gone, or they can no longer add to it)
PUT /api/me/clipboard signed in: {slug} chooses the stash copied text goes to (one you own or can edit; 404 otherwise, 403 when the admin turned the feature off); {slug: null} chooses none. Answers like GET
POST /api/me/stashes follow: {slug, password?, link?} (a link is the token or the whole address; {slug, current: true} follows with the access this browser already has). 401 {locked: true} for a wrong or missing password, counted by the unlock lockout; a drop-box link is 400
DELETE /api/me/stashes/:slug unfollow (the stash is untouched)
POST /api/me/stashes/:slug/seen mark a followed stash as seen now (resets its new count)
POST /api/stashes/:slug/owner pass the stash on to another user: {username} (full access, and only the stash’s owner: 403 for anyone else, an admin included). The user must be an active account other than you; a name that does not exist and an account that is switched off get the same 404. They become the owner, and you stay on as a follower with the access you had until the stash’s password is changed. Answers { ok, owner }
POST /api/admin/stashes/:slug/owner admin: {username} gives a stash that has no owner (a guest made it, or its owner’s account was deleted) to that user (409 when it already has an owner: only the owner can pass it on). On a password-protected stash it is refused (403) while ADMIN_CAN_RESET_STASH_PASSWORDS is off, because the owner can open it without the password. The overview lists canSetOwner for each stash. Answers { ok, owner }
GET /api/admin/users admin: every user with role, status, managed (true for the environment account, which no call below can change: 409), last sign-in and number of followed stashes (never a password or hash)
POST /api/admin/users admin: {username, displayName?, password, role?} (role is admin or user, default user); the answer never echoes the password
PATCH /api/admin/users/:id admin: {role?, disabled?, displayName?}; a role change or disable ends the user’s sessions; refused (400) for your own role or status
POST /api/admin/users/:id/password admin: {password} resets it and ends every session of that user
POST /api/admin/users/:id/sign-out admin: ends every session of that user
DELETE /api/admin/users/:id admin: deletes the user and their follows (not their stashes); refused for your own account

Add preview (true in the body, or ?preview=1) to a listing and notes longer than 2000 characters come back cut to their first 2000, with truncated: true and textLength; fetch the rest from items/:id. The web page does this so a stash of large notes loads quickly. Without preview, text is always complete.

Resumable uploads

A file bigger than 8 MB is sent in 4 MB pieces, so a flaky connection costs one piece instead of the whole file, the page can show real progress, and an upload carries on after the browser is closed or the server restarts. The page and stashly send --file do this by themselves; the protocol is small and works from curl too:

# 1. start: the server checks the name, type, size and quotas now, before any byte is sent
curl -s -X POST http://HOST:3000/api/stashes/NAME/uploads -H "Content-Type: application/json" \
     -d '{"name":"big.zip","size":12345678,"title":"Optional title"}'
#    -> 201 {"id":"<secret>","offset":0,"size":12345678,"chunkSize":4194304}
# 2. send the pieces, each at the offset the server expects (here with split: 4 MB each, in order)
curl -s -X PATCH http://HOST:3000/api/stashes/NAME/uploads/ID -H "Upload-Offset: 0" \
     -H "Content-Type: application/octet-stream" --data-binary @piece-0
# after a failure, ask where it stands and carry on from that offset
curl -sI http://HOST:3000/api/stashes/NAME/uploads/ID | grep -i upload-offset
# 3. finish: only when every byte is there
curl -s -X POST http://HOST:3000/api/stashes/NAME/uploads/ID/complete