The PastePasta API

PastePasta

Publish Markdown, manage drafts and collections, and open posts from tools and scripts. Every path below is relative to /api/v1 on your PastePasta host.

Authentication

Create a token in Settings β†’ API tokens. Copy the full token when it appears and pass it as an Authorization: Bearer header. JSON requests also use Content-Type: application/json. Send Accept: application/json to receive JSON errors.

bash
curl -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Accept: application/json" \
  "http://localhost:8000/api/v1/publications"

An account token can have one or more permissions.

Permission Grants
Read List your posts and collections, fetch a post by its ID, and read posts by address.
Write Create, edit, publish, reorder and delete your posts and collections. Upload images and render previews.
Profile Read and update your account profile.

Ownership applies to management routes. Reader routes accept the web address of any available post and enforce its password or one-time access rules.

Posts

Method and path Permission Result
GET /publications Read 200. Your active drafts and published posts, newest IDs first, 25 per page. Follow the next cursor link when present.
POST /publications Write 201. Creates a post. The Location header points to its owner endpoint.
GET /publications/{publication} Read 200. One of your posts, including Markdown.
PATCH /publications/{publication} Write 200. Updates a post you own. Send only fields to change.
DELETE /publications/{publication} Write 204. Permanently deletes a post and removes its public URL.
PATCH /publications/{publication}/pin Write 204. Send pinned: true or pinned: false for a published post you own.
PATCH /publications/{publication}/position Write 204. Send zero-based position (0–14), optional page (defaults to 1), and optional collection_id. Posts can move within their pinned or unpinned group. Collection ordering must be Manual.

Here {publication} is the post’s id from a management response, a ULID. It is separate from the public slug.

bash
curl -X POST \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  --data '{
    "markdown": "# My first post\n\nHello from the API.",
    "published": false
  }' \
  "http://localhost:8000/api/v1/publications"

To publish, PATCH the returned ID with published: true. Use published: false to move an existing post back to drafts.

Request field Meaning
markdown UTF-8 Markdown, at most 64 KiB. Required and nonempty when publishing. The title is derived from the content.
published Boolean. A new post starts as a draft unless set to true.
visibility public (default) or secret. A secret post is absent from the author’s public profile. Anyone holding its address can open it unless it also has a password.
password Optional reader password. Send null or an empty string to remove it. Omit it when editing to keep the current password.
anonymous Boolean. True omits the author from the public post.
author_name, author_url Optional attribution metadata for the API. A URL requires a name and must use HTTP or HTTPS. Anonymous responses return null for both.
custom_slug Optional address segment up to 64 characters. Use letters, digits and hyphens. Send null for a slug generated from the title and date.
publication_collection_id A collection you own, or null to remove the post from its collection.
lifetime forever, once, hour, day, week, month, or custom. Forever posts expire after a year without a view.
expires_at Future timestamp for a custom lifetime. Send ISO 8601 with a time zone. Example: 2027-01-15T12:00:00Z.

Post responses use a data wrapper. They include the title, status, visibility, author attribution, lifetime, view count and timestamps. url is the browser address and read_url is the reader API address. Both are null for drafts. The management endpoints return id and collection_id, and individual owner responses include custom_slug. A write-only token can create and update posts, but those responses omit Markdown unless it also has Read permission.

Example response

json
{
  "data": {
    "id": "01m95m59ehxgpem3rmr14dhtmp",
    "title": "My first post",
    "status": "draft",
    "visibility": "public",
    "lifetime": "forever",
    "views": 0,
    "url": null,
    "read_url": null
  }
}

This is a shortened example. The API also returns timestamps and the fields allowed by your token.

Reader access

Use read_url from a management response, or take {space}/{identifier} from the post’s browser address. {space} can be a username, a single-letter anonymous section, or secret. Keep the entire secret address private.

Method and path Permission Result
GET /read/{space}/{identifier} Read 200 with rendered HTML and Markdown. Returns 423 if a reader password is required, or 409 with open_url for a one-time post.
POST /read/{space}/{identifier}/unlock Read Send password for a protected post. Returns 200 with the content, or 403 for an incorrect password. For one-time posts, this still returns 409.
POST /read/{space}/{identifier}/open Read Explicitly consumes a one-time post. Send password if required. Returns 200 with content, 409 for a regular post, or 404 after consumption.
json
{
  "password": "example-reader-password"
}

Use GET first when unsure of the access mode. Follow open_url with POST only when you intend to consume the post. Keep that successful response. A subsequent read cannot recover its content. A moved address can return 308 when its redirect is safe to disclose.

Collections

Method and path Permission Result
GET /collections Read 200. Lists your collections in their display order.
POST /collections Write 201. Creates a collection. Send name.
PATCH /collections/{collection} Write 200. Updates one of your collections. Omitted fields keep their values.
PATCH /collections/{collection}/position Write 204. Send position, a zero-based index in your list of collections.
DELETE /collections/{collection} Write 204. Removes the collection. Posts remain available and leave that collection.

{collection} is the numeric ID returned by the collection endpoints. name supports up to 80 characters. Set slug for its public URL, or omit it when creating to generate one from the name. sort_order accepts manual (default), newest, oldest, or popular. Set is_default: true to select the initial collection on the author page, or featured: true to show a shortcut beside its collection selector. A public collection URL is /username/slug and requires an eligible published post.

json
{
  "name": "Field notes",
  "slug": "field-notes",
  "sort_order": "manual",
  "featured": true,
  "is_default": false
}

Images and previews

Method and path Permission Result
POST /images Write 201. Upload a multipart image field. Supports JPEG, PNG, WebP or GIF up to 1 MiB. The response includes id, source, markdown and a temporary preview_url.
POST /preview Write 200. Send markdown and, when previewing an existing post, its optional publication_id. Returns data.html without publishing.
bash
curl -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Accept: application/json" \
  -F "image=@photo.png" \
  "http://localhost:8000/api/v1/images"

Pass publication_id in the multipart form when uploading for an existing post. Uploading the same bytes for that post reuses the existing image. Insert the returned markdown snippet into a post. An unattached upload expires after a day. Public post Markdown contains normal image URLs. Private exports contain temporary signed URLs. One-time images are only available during the short window after opening.

Account profile

Method and path Permission Result
GET /profile Profile 200. Returns username, name and website under data.
PATCH /profile Profile 200. Update any of those fields. Send website: null to clear the link.

Usernames are 3–32 characters, starting with a letter or number. Letters, digits, underscores and hyphens are accepted. Reserved names and usernames already used in published addresses cannot be selected. A website must use HTTP or HTTPS.

Errors

Status Meaning
401 Bearer token missing, expired or invalid.
403 Missing token permission or incorrect reader password.
404 Post or collection unavailable, expired, consumed, or outside your management access.
409 The requested reading action does not match the post’s lifetime. A one-time GET returns open_url.
422 Validation failed. Check errors by field when present.
423 A reader password is required.
429 Rate limited. Wait and retry. The account-wide budget is 120 requests per minute per IP, with lower limits for some actions.
503 Image storage is temporarily unavailable.

Success responses with status 204 have no body. Keep tokens out of published Markdown, client-side code and public logs.

Waiting to sync
1 view

View Markdown