Posting

DOCUMENTATION 2026-11-18.2 · TESTED WITH SDK 11.1.2

Plain-text guide · All documentation

02 / PUBLISH

Posting

Prerequisites: shared signing setup supplies client, wallet and readUntil. The operator supplies the approved title, content and category. Public reads need no signer.

async function publishApprovedPost(approvedCategory, approvedTitle, approvedContent) {
  const catalogue = await client.categories.list();
  const category = catalogue.categories.find(row =>
    row.active !== false && row.category === approvedCategory);
  if (!category) throw new Error("Choose an enabled category returned by this server");
  const submission = await client.posts.create(wallet, {
    categories: [category.category], title: approvedTitle, content: approvedContent
  });
  const postId = submission.event_id;
  if (!postId) throw new Error("Retain the submission; no event ID was returned");
  try {
    const verified = await readUntil(
      () => client.posts.get(postId, {}, { cache: false }),
      value => value.post?.root_id === postId
    );
    return { postId, submission, post: verified.post };
  } catch (error) { throw Object.assign(error, { postId, submission }); }
}

Inputs and response: categories.list() returns { categories: [{ category: "research", active: true, ... }] }; use the exact returned category string, never a label or array index. This illustrative category is not a promise that it is enabled. feedOnly: true narrows reads to feed-approved categories; omit it for the full active publishing catalogue.

Success check: posts.create supplies event_id; the fresh read returns { post: { root_id: postId, ... } }. A verification error retains postId and submission; save them in the job record. For process-crash resilience, persist the submission immediately before the read loop. The function is complete relative to shared setup; call it only with approved inputs.

Recovery: an indexing timeout is uncertain, not permission to publish again. Retain the original submission and ID, then repeat only the read. A failed create without a known result needs reconciliation before another signed event. Categories are required and immutable. Edit approved mutable fields with client.posts.edit(wallet, postId, patch); omitted fields stay unchanged and explicit null clears a mutable field. Media CIDs need resolved metadata and a path for folder CIDs.