Skip to main content

Update an existing post

Use PATCH /v1/posts/{postId} to update an existing post and return the updated post object.
type UpdatePostRequest = {
  title?: string;
  markdown?: string;
  status?: "draft" | "published";
};

type Post = {
  id: string;
  title: string;
  content: string;
  markdown: string;
  recommendations: string | null;
  contentType: string;
  sourceMetadata: unknown;
  status: "draft" | "published";
  createdAt: string;
  updatedAt: string;
};

type UpdatePostResponse = {
  organization: {
    id: string;
    slug: string;
    name: string;
    logo: string | null;
  };
  post: Post;
};

async function updatePost(
  postId: string,
  updates: UpdatePostRequest
): Promise<UpdatePostResponse> {
  const response = await fetch(`https://api.usenotra.com/v1/posts/${postId}`, {
    method: "PATCH",
    headers: {
      "Content-Type": "application/json",
      Authorization: `Bearer ${process.env.NOTRA_API_KEY}`,
    },
    body: JSON.stringify(updates),
  });

  if (!response.ok) {
    throw new Error(`Failed to update post: ${response.status}`);
  }

  return (await response.json()) as UpdatePostResponse;
}

Create a new post

Notra does not currently expose a direct POST /v1/posts endpoint for manually creating a post with arbitrary fields such as author. If you want Notra to create content for you, use POST /v1/posts/generate instead.
If a guide or AI answer suggests POST /v1/posts or an author field for post creation, that information is not correct for the current Notra API.