Skip to content

Blogs

Manage blog posts, authors, and comments.

/api/blogs/
  • Reads are public.
  • Writes depend on staff/ownership rules below.

Permissions Summary

Resource Read Create Update Delete
Authors Anyone Staff only Staff only Staff only
Posts Anyone Staff only Staff only Staff only
Comments Anyone Authenticated users Staff only Staff or comment owner

Authors

GET /api/blogs/authors/

Success (200 OK):

[
  {
    "id": 1,
    "name": "Dr. Jane Doe",
    "title": "Chief Medical Officer",
    "email": "jane@example.com",
    "bio": "Brief bio...",
    "image_url": "https://cdn.example.com/authors/jane.png",
    "image_ref": "authors/jane.png",
    "image_alt": "Dr. Jane Doe",
    "image_title": "Dr. Jane Doe",
    "created_at": "2026-01-19T10:00:00Z",
    "updated_at": "2026-01-19T10:00:00Z"
  }
]
GET /api/blogs/authors/{id}/

Success (200 OK) includes nested posts:

{
  "id": 1,
  "name": "Dr. Jane Doe",
  "title": "Chief Medical Officer",
  "email": "jane@example.com",
  "bio": "Brief bio...",
  "image_url": "https://cdn.example.com/authors/jane.png",
  "image_ref": "authors/jane.png",
  "image_alt": "Dr. Jane Doe",
  "image_title": "Dr. Jane Doe",
  "created_at": "2026-01-19T10:00:00Z",
  "updated_at": "2026-01-19T10:00:00Z",
  "posts": [
    {
      "id": 10,
      "title": "Healthy Living Tips",
      "slug": "healthy-living-tips",
      "featured_image_url": "https://cdn.example.com/posts/healthy-living.png",
      "is_published": true,
      "views": 12,
      "created_at": "2026-01-19T10:00:00Z",
      "updated_at": "2026-01-19T10:00:00Z"
    }
  ]
}
POST /api/blogs/authors/
{
  "name": "Dr. Jane Doe",
  "title": "Chief Medical Officer",
  "email": "jane@example.com",
  "bio": "Brief bio...",
  "image_url": "https://cdn.example.com/authors/jane.png",
  "image_ref": "authors/jane.png",
  "image_alt": "Dr. Jane Doe",
  "image_title": "Dr. Jane Doe"
}

Error (403 Forbidden) if not staff:

{
  "detail": "You do not have permission to perform this action."
}
PUT /api/blogs/authors/{id}/
PATCH /api/blogs/authors/{id}/
{
  "name": "Dr. Jane Doe",
  "title": "Chief Medical Officer",
  "email": "jane@example.com",
  "bio": "Updated bio...",
  "image_url": "https://cdn.example.com/authors/jane.png",
  "image_ref": "authors/jane.png",
  "image_alt": "Dr. Jane Doe",
  "image_title": "Dr. Jane Doe"
}
  • PUT expects the full object (all writable fields).
  • PATCH can send only the fields to change.
DELETE /api/blogs/authors/{id}/

Posts

GET /api/blogs/posts/

Success (200 OK):

[
  {
    "id": 10,
    "title": "Healthy Living Tips",
    "slug": "healthy-living-tips",
    "author": 1,
    "author_name": "Dr. Jane Doe",
    "subcategories": [1, 2],
    "subcategories_details": [
      {"id": 1, "name": "Wellness", "category": 1, "category_name": "Health", "description": "", "created_at": "2026-01-19T10:00:00Z", "updated_at": "2026-01-19T10:00:00Z"},
      {"id": 2, "name": "Nutrition", "category": 1, "category_name": "Health", "description": "", "created_at": "2026-01-19T10:00:00Z", "updated_at": "2026-01-19T10:00:00Z"}
    ],
    "related_products": [1, 5],
    "related_products_details": [
      {"id": 1, "name": "Vitamin D Supplement", "slug": "vitamin-d-supplement", "price": "19.99", "image_urls": []},
      {"id": 5, "name": "Omega-3 Capsules", "slug": "omega-3-capsules", "price": "24.99", "image_urls": []}
    ],
    "content": "Post body...",
    "excerpt": "SEO description up to 160 chars",
    "featured_image_url": "https://cdn.example.com/posts/healthy-living.png",
    "featured_image_ref": "",
    "featured_image_alt": "",
    "featured_image_title": "",
    "meta_keywords": "health,wellness",
    "is_published": true,
    "views": 12,
    "created_at": "2026-01-19T10:00:00Z",
    "updated_at": "2026-01-19T10:00:00Z"
  }
]
GET /api/blogs/posts/{id}/

Success (200 OK) returns the full post object with the same structure as list items:

{
  "id": 10,
  "title": "Healthy Living Tips",
  "slug": "healthy-living-tips",
  "author": 1,
  "author_name": "Dr. Jane Doe",
  "subcategories": [1, 2],
  "subcategories_details": [
    {"id": 1, "name": "Wellness", "category": 1, "category_name": "Health", "description": "", "created_at": "2026-01-19T10:00:00Z", "updated_at": "2026-01-19T10:00:00Z"}
  ],
  "related_products": [1, 5],
  "related_products_details": [
    {"id": 1, "name": "Vitamin D Supplement", "slug": "vitamin-d-supplement", "price": "19.99", "image_urls": []},
    {"id": 5, "name": "Omega-3 Capsules", "slug": "omega-3-capsules", "price": "24.99", "image_urls": []}
  ],
  "content": "Post body...",
  "excerpt": "SEO description up to 160 chars",
  "featured_image_url": "https://cdn.example.com/posts/healthy-living.png",
  "featured_image_ref": "",
  "featured_image_alt": "",
  "featured_image_title": "",
  "meta_keywords": "health,wellness",
  "is_published": true,
  "views": 12,
  "created_at": "2026-01-19T10:00:00Z",
  "updated_at": "2026-01-19T10:00:00Z"
}
POST /api/blogs/posts/
{
  "title": "Healthy Living Tips",
  "author": 1,
  "subcategories": [1, 2],
  "related_products": [1, 5, 8],
  "content": "Post body...",
  "excerpt": "SEO description up to 160 chars",
  "featured_image_url": "https://cdn.example.com/posts/healthy-living.png",
  "featured_image_ref": "s3://bucket/key",
  "featured_image_alt": "alt text",
  "featured_image_title": "image title",
  "meta_keywords": "health,wellness",
  "is_published": true
}

Error (401 Unauthorized) if not authenticated:

{
  "detail": "Authentication credentials were not provided."
}

Error (403 Forbidden) if authenticated but not staff:

{
  "detail": "You do not have permission to perform this action."
}
PUT /api/blogs/posts/{id}/
PATCH /api/blogs/posts/{id}/
{
  "title": "Healthy Living Tips (Updated)",
  "author": 1,
  "subcategories": [1, 2],
  "related_products": [1, 5, 8],
  "content": "Revised post body...",
  "excerpt": "Updated SEO description",
  "featured_image_url": "https://cdn.example.com/posts/healthy-living-updated.png",
  "featured_image_ref": "s3://bucket/new-key",
  "featured_image_alt": "new alt text",
  "featured_image_title": "new image title",
  "meta_keywords": "health,wellness,updated",
  "is_published": true
}
  • PUT expects the full object (all writable fields).
  • PATCH can send only the fields to change.
DELETE /api/blogs/posts/{id}/

Comments

GET /api/blogs/comments/
GET /api/blogs/comments/?post={post_id}

Success (200 OK):

[
  {
    "id": 100,
    "post": 10,
    "author": 1,
    "author_display": "John Doe",
    "content": "Great article!",
    "created_at": "2026-01-19T10:05:00Z",
    "updated_at": "2026-01-19T10:05:00Z"
  }
]
GET /api/blogs/comments/{id}/
POST /api/blogs/comments/
{
  "post": 1,
  "content": "Great article!"
}

Error (401 Unauthorized) if not authenticated:

{
  "detail": "Authentication credentials were not provided."
}
DELETE /api/blogs/comments/{id}/

Notes

  • Unauthenticated users can only read posts and comments.
  • Non-staff authenticated users can create comments; they may delete only their own comments.
  • Only staff can create/update/delete authors and posts, and only staff can edit comments.

Categories & Subcategories

Blogs support categories and subcategories. Categories list and retrieve responses include nested subcategories.

GET /api/blogs/categories/

Success (200 OK):

[
  {
    "id": 1,
    "name": "Health",
    "description": "Health and wellness topics",
    "created_at": "2026-01-19T10:00:00Z",
    "updated_at": "2026-01-19T10:00:00Z",
    "subcategories": [
      {
        "id": 1,
        "name": "Wellness",
        "category": 1,
        "category_name": "Health",
        "description": "",
        "created_at": "2026-01-19T10:00:00Z",
        "updated_at": "2026-01-19T10:00:00Z"
      },
      {
        "id": 2,
        "name": "Nutrition",
        "category": 1,
        "category_name": "Health",
        "description": "",
        "created_at": "2026-01-19T10:00:00Z",
        "updated_at": "2026-01-19T10:00:00Z"
      }
    ]
  }
]
GET /api/blogs/categories/{id}/

Returns the same structure as list items: category fields plus a subcategories array.

GET /api/blogs/subcategories/
GET /api/blogs/subcategories/{id}/

Subcategories have their own endpoints. Each includes category (ID) and category_name.

  • Categories: Staff CRUD at /api/blogs/categories/{id}/ for create, update, delete.
  • Subcategories: Staff CRUD at /api/blogs/subcategories/{id}/ for create, update, delete.
  • A post can belong to multiple subcategories using the subcategories field on the post endpoints.

Posts support a many-to-many relationship with products:

  • related_products (writable): Array of product IDs. Use when creating or updating a post.
  • related_products_details (read-only): Array of lightweight product objects {id, name, slug, price, image_urls} for display.