Ghost CMS Admin API
Manage your Ghost blog posts programmatically through the Admin API.
Features
- - 📝 Create/Update/Delete posts - Full CRUD operations
- 🖼️ Upload images - Upload images to Ghost and get URL
- 🎨 Feature images - Set cover images for posts
- 📊 List posts - View recent posts with status
- 🏷️ Tags support - Add tags to posts
Prerequisites
1. Get Admin API Key
- 1. Log in to your Ghost Admin panel (
https://your-blog.com/ghost/) - Go to Settings → Integrations
- Click "Add custom integration"
- Copy the Admin API Key (format:
id:secret)
2. Create Configuration File
唯一调用方式:自定义配置文件路径(项目隔离)
Create a JSON config file for your site:
Example: /Users/ethan/.openclaw/workspace/projects/fuye/ghost-admin.config.json
CODEBLOCK0
CLI Usage
Method: Custom Config Path (唯一方式)
CODEBLOCK1
Python API Usage
Method: Custom Config Path (唯一方式)
CODEBLOCK2
3. Install Dependencies
CODEBLOCK3
Python API Usage
Create a Post
CODEBLOCK4
Upload Image
CODEBLOCK5
Create Post with Feature Image
CODEBLOCK6
List Posts
CODEBLOCK7
Update Post
CODEBLOCK8
CLI Usage
Setup
CODEBLOCK9
Create a Post
As draft (default):
CODEBLOCK10
Publish immediately:
CODEBLOCK11
With tags:
CODEBLOCK12
Upload Image
CODEBLOCK13
Update a Post
CODEBLOCK14
Delete a Post
CODEBLOCK15
List Posts
CODEBLOCK16
Common Workflows
Publish with Cover Image
CODEBLOCK17
Batch Operations
CODEBLOCK18
API Reference
ghost.getconfig(configpath)
唯一方式获取配置。
Parameters:
- -
config_path - Path to JSON configuration file (e.g., "../../projects/fuye/ghost-admin.config.json")
Returns: Config dict with apiurl and adminapi_key
ghost.createpost(config, title, content, status='draft', tags=None, featureimage=None)
Create a new post.
Parameters:
- -
config - Configuration dict from INLINECODE6 - INLINECODE7 - Post title
- INLINECODE8 - HTML content
- INLINECODE9 - 'draft' or 'published'
- INLINECODE10 - List of tag names
- INLINECODE11 - URL of cover image (optional)
Returns: Post dict with id, url, status
ghost.uploadimage(config, imagepath)
Upload an image to Ghost.
Parameters:
- -
config - Configuration dict - INLINECODE13 - Local path to image file
Returns: Image URL string
ghost.list_posts(config, limit=10)
List recent posts.
Returns: List of post dicts
ghost.updatepost(config, postid, kwargs)
Update existing post.
Parameters:
- -
post_id - Post ID to update - INLINECODE15 - New title (optional)
- INLINECODE16 - New content (optional)
- INLINECODE17 - New status (optional)
- INLINECODE18 - New tags (optional)
ghost.deletepost(config, postid)
Delete a post.
Troubleshooting
Error: No module named 'jwt'
→ Install: INLINECODE19
Error: 401 Unauthorized
→ Check your Admin API Key is correct and not expired
Error: 404 Not Found
→ Verify api_url in config file ends with INLINECODE20
Error: Config file not found
→ Ensure config_path is correct relative to your working directory
Image upload fails
→ Check image file exists and is under 10MB
→ Supported formats: JPG, PNG, GIF
References
- - API Documentation: references/api.md
- Ghost Official Docs: https://ghost.org/docs/admin-api/
Ghost CMS 管理 API
通过管理 API 以编程方式管理您的 Ghost 博客文章。
功能特性
- - 📝 创建/更新/删除文章 - 完整的增删改查操作
- 🖼️ 上传图片 - 上传图片到 Ghost 并获取 URL
- 🎨 特色图片 - 为文章设置封面图片
- 📊 文章列表 - 查看最近文章及其状态
- 🏷️ 标签支持 - 为文章添加标签
前置条件
1. 获取管理 API 密钥
- 1. 登录您的 Ghost 管理面板(https://your-blog.com/ghost/)
- 进入 设置 → 集成
- 点击 添加自定义集成
- 复制 管理 API 密钥(格式:id:secret)
2. 创建配置文件
唯一调用方式:自定义配置文件路径(项目隔离)
为您的站点创建一个 JSON 配置文件:
示例:/Users/ethan/.openclaw/workspace/projects/fuye/ghost-admin.config.json
json
{
api_url: https://fu-ye.com/ghost/api/admin,
adminapikey: your-id:your-secret
}
CLI 使用方式
方法:自定义配置路径(唯一方式)
bash
python3 scripts/ghost.py list --config ../../projects/fuye/ghost-admin.config.json
python3 scripts/ghost.py create 标题 内容 --config ../../projects/fuye/ghost-admin.config.json
python3 scripts/ghost.py upload image.png --config ../../projects/fuye/ghost-admin.config.json
Python API 使用方式
方法:自定义配置路径(唯一方式)
python
import sys
import os
sys.path.insert(0, os.path.expanduser(~/.openclaw/workspace/skills/ghost/scripts))
import ghost
唯一方式:通过配置文件路径获取配置
config = ghost.get
config(configpath=../../projects/fuye/ghost-admin.config.json)
创建文章
result = ghost.create_post(
config=config,
title=我的文章标题,
content=
标题
内容...
,
status=published,
tags=[技术, 新闻]
)
3. 安装依赖
bash
pip3 install requests pyjwt --user
Python API 使用方式
创建文章
python
import sys
import os
sys.path.insert(0, os.path.expanduser(~/.openclaw/workspace/skills/ghost/scripts))
import ghost
通过配置文件路径获取配置(唯一方式)
config = ghost.get
config(configpath=../../projects/fuye/ghost-admin.config.json)
使用 HTML 内容创建文章
result = ghost.create_post(
config=config,
title=我的文章标题,
content=
标题
内容...
, # HTML 格式
status=published, # 或 draft
tags=[技术, 新闻]
)
上传图片
python
上传图片并获取 URL
image
url = ghost.uploadimage(config, /path/to/image.jpg)
print(f图片 URL: {image_url})
创建带特色图片的文章
python
先上传封面图片
cover
imageurl = ghost.upload_image(config, cover.jpg)
创建带特色图片的文章
result = ghost.create_post(
config=config,
title=带封面的文章,
content=
文章内容...
,
status=published,
feature
image=coverimage_url, # 设置封面图片
tags=[精选]
)
文章列表
python
posts = ghost.list_posts(config, limit=20)
for post in posts:
print(f{post[title]} - {post[status]})
更新文章
python
ghost.update_post(
config=config,
post_id=文章ID,
title=新标题,
status=published
)
CLI 使用方式
设置
bash
安装依赖
pip3 install requests pyjwt --user
创建文章
保存为草稿(默认):
bash
python3 scripts/ghost.py create 我的文章标题
HTML格式的文章内容
--config ../../projects/fuye/ghost-admin.config.json
立即发布:
bash
python3 scripts/ghost.py create 突发新闻
内容在这里
--status published --config ../../projects/fuye/ghost-admin.config.json
带标签:
bash
python3 scripts/ghost.py create 科技新闻
内容
--status published --tags 科技,新闻,AI --config ../../projects/fuye/ghost-admin.config.json
上传图片
bash
python3 scripts/ghost.py upload cover.png --config ../../projects/fuye/ghost-admin.config.json
更新文章
bash
更新标题
python3 scripts/ghost.py update 5f8c3c2e8c3d2e1f3a4b5c6d --title 新标题 --config ../../projects/fuye/ghost-admin.config.json
更新内容
python3 scripts/ghost.py update 5f8c3c2e8c3d2e1f3a4b5c6d --content
新内容
--config ../../projects/fuye/ghost-admin.config.json
发布草稿
python3 scripts/ghost.py update 5f8c3c2e8c3d2e1f3a4b5c6d --status published --config ../../projects/fuye/ghost-admin.config.json
删除文章
bash
python3 scripts/ghost.py delete 5f8c3c2e8c3d2e1f3a4b5c6d --config ../../projects/fuye/ghost-admin.config.json
文章列表
bash
列出最近10篇文章(默认)
python3 scripts/ghost.py list --config ../../projects/fuye/ghost-admin.config.json
列出20篇文章
python3 scripts/ghost.py list 20 --config ../../projects/fuye/ghost-admin.config.json
常见工作流程
发布带封面图片的文章
python
import sys
import os
sys.path.insert(0, os.path.expanduser(~/.openclaw/workspace/skills/ghost/scripts))
import ghost
唯一方式:通过配置文件路径获取配置
config = ghost.get
config(configpath=../../projects/fuye/ghost-admin.config.json)
上传封面图片
image
url = ghost.uploadimage(config, /path/to/cover.jpg)
创建带封面的文章
result = ghost.create_post(
config=config,
title=精选文章,
content=
文章内容...
,
status=published,
feature
image=imageurl,
tags=[精选, 技术]
)
print(f已发布: {result[url]})
批量操作
bash
列出所有草稿
python3 scripts/ghost.py list 100 --config ../../projects/fuye/ghost-admin.config.json | grep 🟡
更新特定文章
python3 scripts/ghost.py update
--tags 精选 --config ../../projects/fuye/ghost-admin.config.json
API 参考
ghost.getconfig(configpath)
唯一方式获取配置。
参数:
- - config_path - JSON 配置文件路径(例如:../../projects/fuye/ghost-admin.config.json)
返回: 包含 apiurl 和 adminapi_key 的配置字典
ghost.createpost(config, title, content, status=draft, tags=None, featureimage=None)
创建新文章。
参数:
- - config - 从 getconfig(configpath) 获取的配置字典
- title - 文章标题
- content - HTML 内容
- status - draft 或 published
- tags - 标签名称列表
- feature_image - 封面图片 URL(可选)
返回: 包含 id、url、status 的文章字典
ghost.uploadimage(config, imagepath)
上传图片到 Ghost。
参数:
- - config - 配置字典
- image_path - 图片文件的本地路径
返回: 图片 URL 字符串
ghost.list_posts(config, limit=10)
列出最近文章。
返回: 文章字典列表
ghost.updatepost(config, postid, kwargs)
更新现有文章。
参数:
- - post_id - 要更新的文章 ID
- title -