Get All Blog Posts
Retrieve a list of blog posts with optional filtering, searching, and pagination.
HTTP Request
GET/api/blog/posts
Authorization
Authorization
- Required: Yes
- Permission: Staff or Admin
- Authentication: Token-based (Authorization: Token <your_api_key>)
Query Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
| limit | integer | — | Number of results to return per page. |
| offset | integer | — | Number of results to skip before returning results. |
| search | string | — | Search term to filter results by `id`, `slug`, `title`, `body`, `author__id`, `author__username`, `author__email`, `author__first_name`, `author__last_name`. |
| ordering | string | — | Field to order results by (`id`, `title`, `views`, `created_at`, `updated_at`, `author__id`, `author__username`, `author__first_name`, `author__last_name`). |
| views_min | integer | — | Minimum number of views to filter results by. |
| views_max | integer | — | Maximum number of views to filter results by. |
| has_image | boolean | — | Filter results to only include posts with a featured image. |
| id_min | integer | — | Minimum ID to filter results by. |
| id_max | integer | — | Maximum ID to filter results by. |
| created_date | string | — | Filter results by creation date (e.g., `2023-01-01`). |
| updated_date | string | — | Filter results by last updated date (e.g., `2023-01-01`). |
| created_from | string | — | Filter results by creation date range (e.g., `2023-01-01` to `2023-12-31`). |
| created_to | string | — | Filter results by creation date range (e.g., `2023-01-01` to `2023-12-31`). |
| updated_from | string | — | Filter results by last updated date range (e.g., `2023-01-01` to `2023-12-31`). |
| updated_to | string | — | Filter results by last updated date range (e.g., `2023-01-01` to `2023-12-31`). |
Example Requests
- 🐍 Python
- 🌐 Curl
1import requests
2response = requests.get('http://www.example.com/api/blog/posts', params={
3 'limit': 5,
4 'ordering': 'created_at',
5 'search': 'Python',
6 'views_min': 100,
7 'views_max': 1000,
8 'has_image': True,
9 'created_from': '2023-01-01',
10 'created_to': '2023-12-31'
11})
12print(response.json())1curl "http://www.example.com/api/blog/posts?limit=5&ordering=created_at&search=Python&views_min=100&views_max=1000&has_image=true&created_from=2023-01-01&created_to=2023-12-31"Status Codes
| Code | Description |
|---|---|
| 200 | Blog posts retrieved successfully |
| 400 | Bad request — invalid parameters |
| 401 | Unauthorized — authentication required |
| 403 | Forbidden — insufficient permissions |
| 500 | Internal server error |
Response Fields
| Field | Type | Description |
|---|---|---|
| id | Integer | Unique ID of the blog post |
| title | String | Title of the blog post |
| slug | String | Slug for the blog post |
| views | Integer | Number of views the blog post has received |
| human_readable_views | String | Human-readable format of the views (e.g., 1.2K) |
| excerpt | String | Short summary or excerpt of the blog post |
| truncated_excerpt | String | Truncated version of the excerpt (e.g., first 100 characters) |
| author_data | Object | Author details including `id`, `username`, and `full_name` |
| featured_image_data | Object | Featured image data including `id`, `type`, `name`, `size`, `human_readable_size`, `f`, `width`, `height`, and `mode` |
| body | String | Full content of the blog post |
| truncated_body | String | Truncated version of the body (e.g., first 200 characters) |
| created_at | String (ISO 8601) | Timestamp when the blog post was created |
| updated_at | String (ISO 8601) | Timestamp when the blog post was last updated |
Author Data Structure
| Field | Type | Description |
|---|---|---|
| id | Integer | Unique ID of the author |
| username | String | Username of the author |
| full_name | String | Full name of the author (first and last name combined) |
Featured Image Data Structure
| Field | Type | Description |
|---|---|---|
| id | Integer | Unique ID of the featured image |
| type | String | File type (e.g., image/jpeg) |
| name | String | Original file name |
| size | Integer | File size in bytes |
| human_readable_size | String | Human readable file size (e.g., 2.5 MB) |
| f | String | URL to access the image file |
| width | Integer | Image width in pixels |
| height | Integer | Image height in pixels |
| mode | String | Color mode (e.g., RGB, CMYK) |