Skip to content

Blog Posts

The Konigle SDK provides comprehensive blog post management for creating and managing blog content. Blog posts support rich EditorJS content, SEO metadata, author attribution, and collaboration features.

Creating Blog Posts

Basic Blog Post Creation

import konigle

client = konigle.Client(api_key="your-api-key")

# Create a simple blog post
blog_data = konigle.models.BlogCreate(
    title="Getting Started with Our Platform",
    name="Getting Started Guide",
    handle="getting-started-guide",
    summary="Learn the basics of using our platform effectively",
    content={
        "time": 1672531200000,
        "blocks": [
            {
                "id": "header1",
                "type": "header",
                "data": {"text": "Introduction", "level": 2}
            },
            {
                "id": "paragraph1",
                "type": "paragraph",
                "data": {
                    "text": "Welcome to our platform! This guide will help you get started with all the essential features you need to know."
                }
            }
        ],
        "version": "2.28.2"
    }
)

blog_post = client.blogs.create(blog_data)
print(f"Created blog post: {blog_post.id}")

Blog Post with Auto-generated Handle

# Handle will be auto-generated from title if not provided
blog_data = konigle.models.BlogCreate(
    title="Exciting New Features This Month",
    name="Platform Updates",
    summary="We've added several new features to improve your experience",
    content={
        "time": 1672531200000,
        "blocks": [
            {
                "id": "paragraph1",
                "type": "paragraph",
                "data": {"text": "This month brings exciting updates to our platform..."}
            }
        ],
        "version": "2.28.2"
    }
)

blog_post = client.blogs.create(blog_data)
print(f"Auto-generated handle: {blog_post.handle}")

Blog Post with SEO Metadata

from konigle.models import SEOMeta

# Create blog post with complete SEO optimization
blog_data = konigle.models.BlogCreate(
    title="SEO Best Practices for 2024",
    name="SEO Best Practices",
    handle="seo-best-practices-2024",
    summary="Essential SEO strategies to improve your website's search engine ranking",
    content={
        "time": 1672531200000,
        "blocks": [
            {
                "id": "paragraph1",
                "type": "paragraph",
                "data": {"text": "Search engine optimization continues to evolve..."}
            }
        ],
        "version": "2.28.2"
    },
    seo_meta=SEOMeta(
        title="SEO Best Practices for 2024 | Marketing Blog",
        description="Discover the latest SEO strategies and best practices to boost your website's search rankings in 2024",
        keywords="seo,search engine optimization,2024,digital marketing,ranking,website"
    ),
    json_ld={
        "@context": "https://schema.org",
        "@type": "BlogPosting",
        "headline": "SEO Best Practices for 2024",
        "description": "Essential SEO strategies to improve your website's search engine ranking",
        "keywords": "SEO, digital marketing, search optimization"
    }
)

blog_post = client.blogs.create(blog_data)
print(f"SEO-optimized blog post created: {blog_post.title}")

Blog Post with Author and Collaboration

# Create blog post with author and contributors
blog_data = konigle.models.BlogCreate(
    title="Building Effective Remote Teams",
    name="Team Collaboration Guide",
    handle="remote-team-collaboration",
    summary="Learn how to build and manage high-performing remote teams",
    content={
        "time": 1672531200000,
        "blocks": [
            {
                "id": "paragraph1",
                "type": "paragraph",
                "data": {"text": "Remote work has become the new normal..."}
            }
        ],
        "version": "2.28.2"
    },
    author="author_123456789",
    contributor_ids=["author_111", "author_222"],
    reviewer_ids=["author_333"],
    show_author=True
)

blog_post = client.blogs.create(blog_data)
print(f"Collaborative blog post created: {blog_post.title}")

Blog Post in Specific Folder

# Create blog post in a specific folder/category
blog_data = konigle.models.BlogCreate(
    title="Mastering Advanced Features",
    name="Product Tutorial",
    folder="folder_tutorials",  # Place in tutorials folder
    summary="Comprehensive tutorial on advanced features and capabilities",
    content={
        "time": 1672531200000,
        "blocks": [
            {
                "id": "paragraph1",
                "type": "paragraph",
                "data": {"text": "In this tutorial, we'll explore advanced features..."}
            }
        ],
        "version": "2.28.2"
    }
)

blog_post = client.blogs.create(blog_data)
print(f"Blog post created in folder: {blog_post.folder}")

Note the the folder must be a blog folder type.

Listing Blog Posts

Basic Blog Post Listing

# List all blog posts with pagination
blog_posts = client.blogs.list(page=1, page_size=20)

print(f"Total blog posts: {blog_posts.count}")
print(f"Current page: {blog_posts.current_page}")
print(f"Total pages: {blog_posts.total_pages}")

for post in blog_posts.payload:
    print(f"- {post.title}")
    print(f"  Handle: {post.handle}")
    print(f"  Published: {post.published}")
    print(f"  Summary: {post.summary[:100]}...")

Filtering Blog Posts

from konigle.filters.website import BlogFilters

# Using filter object
blog_filters = BlogFilters(
    q="tutorial",  # Search in title and name
    folder="folder_123",  # Filter by folder
    published=True,
    ordering="-published_at"  # Sort by newest published first
)

filtered_posts = client.blogs.list(
    page=1,
    page_size=10,
    filters=blog_filters
)

# Filter published posts
published_posts = client.blogs.list(
    filters=BlogFilters(published=True, ordering="-created_at")
)

# Filter by folder/category
tutorial_posts = client.blogs.list(
    filters=BlogFilters(folder="folder_tutorials")
)

# Search blog posts
search_results = client.blogs.list(
    filters=BlogFilters(q="getting started")
)

Getting a Specific Blog Post

# Get blog post by ID
blog_post = client.blogs.get("blog_123456789")
print(f"Blog Post: {blog_post.title}")
print(f"Author: {blog_post.author}")
print(f"Summary: {blog_post.summary}")
print(f"Contributors: {len(blog_post.contributors)}")
print(f"Published: {blog_post.published}")
if blog_post.published_at:
    print(f"Published at: {blog_post.published_at}")

Updating Blog Posts

# Update blog post metadata
update_data = konigle.models.BlogUpdate(
    title="Updated: SEO Best Practices for 2024",
    summary="Updated SEO strategies with the latest best practices and algorithm changes"
)

updated_post = client.blogs.update("blog_123456789", update_data)
print(f"Updated blog post: {updated_post.title}")

# Update blog post content
content_update = konigle.models.BlogUpdate(
    content={
        "time": 1672531200000,
        "blocks": [
            {
                "id": "header1",
                "type": "header",
                "data": {"text": "Updated Content", "level": 1}
            },
            {
                "id": "paragraph1",
                "type": "paragraph",
                "data": {"text": "This blog post has been updated with the latest information and insights."}
            }
        ],
        "version": "2.28.2"
    }
)

post_with_new_content = client.blogs.update("blog_123456789", content_update)

# Update contributors and reviewers
collaboration_update = konigle.models.BlogUpdate(
    contributor_ids=["author_111", "author_222", "author_444"],
    reviewer_ids=["author_333", "author_555"],
    show_author=True
)

collaborative_post = client.blogs.update("blog_123456789", collaboration_update)

Deleting Blog Posts

# Delete a blog post
client.blogs.delete("blog_123456789")
print("Blog post deleted successfully")

Blog Actions

Publishing and Unpublishing Blog Posts

# Publish a blog post to make it live on your website
blog_post = client.blogs.get("blog_123456789")
published_post = blog_post.publish()
print(f"Blog post published: {published_post.published}")
print(f"Published at: {published_post.published_at}")

# Or use the manager directly
published_post = client.blogs.publish("blog_123456789")

# Unpublish a blog post to take it offline
unpublished_post = blog_post.unpublish()
print(f"Blog post unpublished: {unpublished_post.published}")

# Or use the manager directly
unpublished_post = client.blogs.unpublish("blog_123456789")

Changing Blog Post Handles

# Change a blog post's URL handle
blog_post = client.blogs.get("blog_123456789")

# Change handle without redirect
updated_post = blog_post.change_handle("new-blog-handle")
print(f"New handle: {updated_post.handle}")

# Change handle with redirect from old URL
updated_post = blog_post.change_handle("better-handle", redirect=True)
print(f"Handle changed to: {updated_post.handle}")
print("Redirect created from old handle")

CLI Usage

Use the CLI for quick blog management:

# Create blog with content file
konigle blogs create \
  --title "My First Blog Post" \
  --name "first-post" \
  --summary "Introduction to our platform" \
  --content-file ./sample-blog-content.json \
  --author "author_123" \
  --folder "folder_456"

# Create blog with inline content JSON
konigle blogs create \
  --title "Quick Update" \
  --content '{"blocks":[{"type":"paragraph","data":{"text":"Hello world!"}}]}'

# List blogs
konigle blogs list --page 1 --page-size 20
konigle blogs list --folder "folder_tutorials" --published

# Get specific blog
konigle blogs get blog_123456789

# Update blog
konigle blogs update blog_123456789 \
  --title "Updated Title" \
  --content-file ./updated-content.json

# Update with SEO and JSON-LD
konigle blogs update blog_123456789 \
  --seo '{"title":"SEO Title","description":"SEO description"}' \
  --json-ld '{"@type":"BlogPosting","headline":"My Post"}'

# Delete blog
konigle blogs delete blog_123456789 --yes

Working with EditorJS Content

Creating Rich Content

def create_tutorial_content(title: str, steps: list) -> dict:
    """Create tutorial-style EditorJS content."""
    blocks = [
        {
            "id": "header1",
            "type": "header",
            "data": {"text": title, "level": 1}
        },
        {
            "id": "intro",
            "type": "paragraph",
            "data": {"text": "Follow these steps to complete the tutorial:"}
        }
    ]

    for i, step in enumerate(steps, 1):
        blocks.extend([
            {
                "id": f"step_{i}_header",
                "type": "header",
                "data": {"text": f"Step {i}: {step['title']}", "level": 2}
            },
            {
                "id": f"step_{i}_content",
                "type": "paragraph",
                "data": {"text": step["description"]}
            }
        ])

    return {
        "time": 1672531200000,
        "blocks": blocks,
        "version": "2.28.2"
    }

# Usage
tutorial_steps = [
    {
        "title": "Setup Your Environment",
        "description": "First, make sure you have all the necessary tools installed."
    },
    {
        "title": "Configure Settings",
        "description": "Next, configure the basic settings for optimal performance."
    }
]

tutorial_content = create_tutorial_content("Development Setup Guide", tutorial_steps)

blog_post = client.blogs.create(konigle.models.BlogCreate(
    title="Development Setup Guide",
    name="dev-setup-tutorial",
    content=tutorial_content,
    folder="folder_tutorials"
))

Loading Content from File

import json

# Load EditorJS content from file
with open("blog-content.json", "r") as f:
    content_data = json.load(f)

blog_data = konigle.models.BlogCreate(
    title="Blog from File",
    name="blog-from-file",
    content=content_data,
    summary="Blog post created from external content file"
)

blog_post = client.blogs.create(blog_data)

Async Operations

import asyncio

async def manage_blog_posts():
    async with konigle.AsyncClient(api_key="your-api-key") as client:
        # Create blog post
        blog_data = konigle.models.BlogCreate(
            title="Async Blog Post",
            name="async-blog",
            summary="Created using async operations"
        )
        blog_post = await client.blogs.create(blog_data)

        # List blog posts
        posts = await client.blogs.list(page_size=10)

        # Update blog post
        update_data = konigle.models.BlogUpdate(title="Updated Async Blog Post")
        updated_post = await client.blogs.update(blog_post.id, update_data)

        # Delete blog post
        await client.blogs.delete(blog_post.id)

asyncio.run(manage_blog_posts())