Sei
FeaturesIntegrationsFAQ
Start
  • Overview
  • WordPress
  • Custom site quick start
Reference
  • Operations
  • Webhook protocol
  • @getsei/webhook
  • @getsei/payload
Help
  • Troubleshooting
  • Changelog

Docs

Custom site quick start

Any site can receive Sei's articles through one endpoint. This page sets one up in Next.js; the same handler runs on any server with Request and Response, and Express has an adapter.

1. Install

npm i @getsei/webhook

2. Add the endpoint

// app/api/sei/webhook/route.ts
import { createSeiHandler } from "@getsei/webhook/next";
import { db } from "@/lib/db"; // your storage

export const POST = createSeiHandler({
  // Read per request: a rotated secret needs no restart.
  secret: () => process.env.SEI_WEBHOOK_SECRET,
  onPing: () => ({ name: "My blog", capabilities: ["drafts"] }),
  async onPublish({ article, mode }) {
    const post = await db.posts.upsertBySeiId(article.seiId, {
      title: article.title,
      slug: article.slug,
      html: article.contentHtml,
      seoTitle: article.seoTitle,
      metaDescription: article.metaDescription,
      coverUrl: article.featuredImage?.url,
      published: mode === "publish",
    });
    return {
      externalId: post.id,
      revision: String(post.updatedAt.getTime()),
      status: mode === "publish" ? "published" : "draft",
      url: `https://blog.example/${post.slug}`,
    };
  },
});

Render contentHtml through your usual HTML sanitizer, or build your own markup from contentBlocks.

3. Connect it in Sei

  1. Sites → Add a site, platform Custom site.
  2. Enter the endpoint's full URL, for example https://blog.example/api/sei/webhook.
  3. Generate secret, put it in SEI_WEBHOOK_SECRET on your server, and deploy.
  4. Check connection. Sei sends ping and shows what your site can do.

4. Add what you need

Each handler you add switches a feature on in Sei:

Handler Feature in Sei
onUnpublish Unpublish
onList Import your existing articles
onTerms Your categories and tags in Sei's pickers
onDelete "Also delete it on your site" when deleting
onRestore Restore brings the article back on your site too
onPing with capabilities: ["drafts", "schedule"] Save as draft, Schedule

Preview needs no handler: Sei loads one of your published articles' pages and puts the draft in its place, in your site's own look (scripts are switched off). A site with nothing published yet gets Sei's plain preview.

Operations says what each one receives and returns, and the protocol has every field. A complete receiver, with soft delete, drafts, categories, tags and the cover image, runs the demo blog at getsei-demo.vercel.app.

On this page
  • 1. Install
  • 2. Add the endpoint
  • 3. Connect it in Sei
  • 4. Add what you need
PrivacyTermsDocsSeiBot