dzen.nstarikov.ru/docs/superpowers/specs/2026-10-18-draft-update-api-design.md
nstarikov 367e772e65
Some checks failed
Deploy Dzen assistant / deploy (push) Failing after 0s
Add safe external draft update API
2026-10-18 15:12:44 +03:00

1.9 KiB

External Draft Update API Design

Goal

Allow trusted integrations to update editorial fields of an existing unpublished Dzen Assistant draft through the documented /api/v1 contract, without granting publication, deletion, scheduling, status, or video-association capabilities.

Endpoint

PATCH /api/v1/drafts/{article_id} uses the existing global draft API key and returns the same complete draft payload as the create/read endpoints.

The request may contain any non-empty subset of:

  • title
  • slug
  • lead
  • bodyHtml
  • featureImageUrl
  • ctaHtml

Unknown fields remain rejected by Pydantic. An empty object returns 422.

Safety boundaries

  • Only articles with status == "draft" and published_at is None may be updated.
  • The endpoint never accepts or mutates status, publishedAt, videoId, createdAt, or publication/scheduling fields.
  • Missing or rejected articles return 404.
  • A non-draft or already-published article returns 409.
  • Title, slug, image URL, and HTML use the same normalization and sanitization rules as draft creation.
  • A slug already owned by another article returns 409.
  • The existing video_id relationship remains unchanged.

Data flow

The handler authenticates the API key, loads the article, applies guard clauses, validates only supplied fields, sanitizes HTML, commits one transaction, refreshes the record, and returns draft_api_payload. IntegrityError is rolled back and mapped to a deterministic slug conflict when applicable.

Verification

Unit tests cover authentication, partial updates, HTML sanitization, invalid and duplicate slugs, invalid cover URLs, empty payloads, rejection of published/non-draft articles, and preservation of video/status/publication fields. Production verification checks OpenAPI exposure, performs read-back around the three intended draft updates, and confirms each remains a draft with its original video and one rendered VK iframe.