Skip to main content

Get All Posts

Retrieve a list of all posts.
export async function getAllPosts(): Promise<Post[]>

Response

Returns an array of Post objects.
[
  {
    "id": 1,
    "title": "Getting Started with Blog Marketing",
    "slug": "getting-started-with-blog-marketing",
    "excerpt": "Learn the fundamentals of blog marketing...",
    "status": "published",
    "authorId": 3,
    "author": {
      "id": 3,
      "name": "Jane Doe",
      "avatar": "https://ui-avatars.com/api/?name=Jane+Doe"
    },
    "views": 1247,
    "likes": 89,
    "createdAt": "2024-01-15T10:30:00Z",
    "publishedAt": "2024-01-16T08:00:00Z"
  }
]

Get Post by ID

Retrieve a single post by its ID.
export async function getPostById(postId: number): Promise<Post | null>

Parameters

postId
number
required
The unique identifier of the post

Response

Returns a Post object or null if not found.

Get Complete Posts

Retrieve posts with all relations (categories, keywords, author details).
export async function getPostsCompletos(limit: number = 20): Promise<Post[]>

Parameters

limit
number
default:"20"
Maximum number of posts to return

Response

Returns an array of Post objects with all related data populated.

Create Post

Create a new blog post.
export async function createPost(postData: Partial<Post>): Promise<Post>

Request Body

title
string
required
Post title (required)
content
string
required
Post content (HTML or Markdown)
slug
string
Custom URL slug (auto-generated from title if not provided)
excerpt
string
Short description of the post
status
string
default:"draft"
Initial status: draft, published, pending, or rejected
categoryId
number
Primary category ID
tags
array
Array of tag strings (will be converted to keywords)
URL to featured image
Mark as featured post
allowComments
boolean
default:"true"
Enable comments on this post
isPinned
boolean
default:"false"
Pin post to top of listings
seo
object
SEO metadata object

Response

Returns the created Post object with generated ID and timestamps.

Update Post

Update an existing post. Partial updates are supported.
export async function updatePost(
  postId: number,
  postData: Partial<Post>
): Promise<Post | null>

Parameters

postId
number
required
ID of the post to update
postData
Partial<Post>
required
Object containing fields to update (only include fields you want to change)

Response

Returns the updated Post object or null if not found.

Update Post Status

Change the status of a post.
export async function updatePostStatus(
  postId: number,
  newStatus: 'draft' | 'published' | 'pending' | 'rejected'
): Promise<Post | null>

Parameters

postId
number
required
ID of the post to update
newStatus
string
required
New status: draft, published, pending, or rejected

Response

Returns the updated Post object with new status.

Delete Post

Permanently delete a post.
export async function deletePost(postId: number): Promise<boolean>

Parameters

postId
number
required
ID of the post to delete

Response

Returns true if deletion was successful, false otherwise.
Post deletion is permanent and cannot be undone. Consider archiving posts instead by setting status to rejected.

Bulk Actions

Perform actions on multiple posts at once.
export async function bulkAction(
  ids: number[],
  action: 'publish' | 'draft' | 'delete'
): Promise<void>

Parameters

ids
number[]
required
Array of post IDs to perform action on
action
string
required
Action to perform: publish, draft, or delete

Actions

  • publish - Changes status to published
  • draft - Changes status to draft
  • delete - Permanently deletes the posts

Upload and set a featured image for a post.
export async function uploadPostFeaturedImage(
  postId: number,
  file: File
): Promise<{ featuredImageUrl: string }>

Parameters

postId
number
required
ID of the post
file
File
required
Image file to upload (JPEG, PNG, WebP supported)

Response

URL of the uploaded image

Helper Functions

Get Pending Posts

Get all posts awaiting review.
export function getPendingPosts(): Post[]
Returns an array of posts with status pending. Useful for review queues and notifications.
This function works with the local store in mock mode. In production, use getAllPosts() and filter by status.

Build docs developers (and LLMs) love