WikiJS提供了一套完整的GraphQL API,可用于查询和修改系统中的各种资源。本文档将对主要的API模块进行解析并提供调用示例。
WikiJS的GraphQL API端点通常为:
https://<your-wiki-domain>/graphql
大多数API请求需要身份验证,通过以下两种方式之一:
JWT令牌:通过登录API获取JWT令牌,然后在请求头中添加:
Authorization: Bearer <your-jwt-token>
API密钥:通过管理界面创建API密钥,然后在请求头中添加:
Authorization: Bearer <your-api-key>
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "YOUR_GRAPHQL_QUERY"}' \
https://your-wiki-domain/graphql
query {
authentication {
strategies {
key
title
description
isAvailable
}
apiState
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-d '{"query": "query { authentication { strategies { key title description isAvailable } apiState } }"}' \
https://your-wiki-domain/graphql
query {
authentication {
activeStrategies(enabledOnly: true) {
key
displayName
order
isEnabled
strategy {
key
title
}
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "query { authentication { activeStrategies(enabledOnly: true) { key displayName order isEnabled strategy { key title } } } }"}' \
https://your-wiki-domain/graphql
mutation {
authentication {
login(
username: "your-username"
password: "your-password"
strategy: "local"
) {
responseResult {
succeeded
errorCode
slug
message
}
jwt
mustChangePwd
mustProvideTFA
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-d '{"query": "mutation { authentication { login(username: \"your-username\", password: \"your-password\", strategy: \"local\") { responseResult { succeeded errorCode slug message } jwt mustChangePwd mustProvideTFA } } }"}' \
https://your-wiki-domain/graphql
mutation {
authentication {
register(
email: "new.user@example.com"
password: "SecurePassword123"
name: "New User"
) {
responseResult {
succeeded
errorCode
slug
message
}
jwt
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-d '{"query": "mutation { authentication { register(email: \"new.user@example.com\", password: \"SecurePassword123\", name: \"New User\") { responseResult { succeeded errorCode slug message } jwt } } }"}' \
https://your-wiki-domain/graphql
mutation {
authentication {
forgotPassword(
email: "user@example.com"
) {
responseResult {
succeeded
errorCode
slug
message
}
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-d '{"query": "mutation { authentication { forgotPassword(email: \"user@example.com\") { responseResult { succeeded errorCode slug message } } } }"}' \
https://your-wiki-domain/graphql
mutation {
authentication {
loginTFA(
continuationToken: "token-from-login-response"
securityCode: "123456"
setup: false
) {
responseResult {
succeeded
errorCode
slug
message
}
jwt
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-d '{"query": "mutation { authentication { loginTFA(continuationToken: \"token-from-login-response\", securityCode: \"123456\", setup: false) { responseResult { succeeded errorCode slug message } jwt } } }"}' \
https://your-wiki-domain/graphql
mutation {
authentication {
loginChangePassword(
continuationToken: "token-from-login-response"
newPassword: "NewSecurePassword123"
) {
responseResult {
succeeded
errorCode
slug
message
}
jwt
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-d '{"query": "mutation { authentication { loginChangePassword(continuationToken: \"token-from-login-response\", newPassword: \"NewSecurePassword123\") { responseResult { succeeded errorCode slug message } jwt } } }"}' \
https://your-wiki-domain/graphql
mutation {
authentication {
createApiKey(
name: "My API Key"
expiration: "2025-12-31"
fullAccess: true
) {
responseResult {
succeeded
}
key
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
-d '{"query": "mutation { authentication { createApiKey(name: \"My API Key\", expiration: \"2025-12-31\", fullAccess: true) { responseResult { succeeded } key } } }"}' \
https://your-wiki-domain/graphql
mutation {
authentication {
revokeApiKey(id: 1) {
responseResult {
succeeded
message
}
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "mutation { authentication { revokeApiKey(id: 1) { responseResult { succeeded message } } } }"}' \
https://your-wiki-domain/graphql
mutation {
authentication {
setApiState(enabled: true) {
responseResult {
succeeded
message
}
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "mutation { authentication { setApiState(enabled: true) { responseResult { succeeded message } } } }"}' \
https://your-wiki-domain/graphql
mutation {
authentication {
updateStrategies(
strategies: [
{
key: "local"
strategyKey: "local"
displayName: "本地账户"
order: 1
isEnabled: true
selfRegistration: true
domainWhitelist: []
autoEnrollGroups: [2]
config: []
}
]
) {
responseResult {
succeeded
message
}
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "mutation { authentication { updateStrategies(strategies: [{key: \"local\", strategyKey: \"local\", displayName: \"本地账户\", order: 1, isEnabled: true, selfRegistration: true, domainWhitelist: [], autoEnrollGroups: [2], config: []}]) { responseResult { succeeded message } } } }"}' \
https://your-wiki-domain/graphql
mutation {
authentication {
regenerateCertificates {
responseResult {
succeeded
message
}
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "mutation { authentication { regenerateCertificates { responseResult { succeeded message } } } }"}' \
https://your-wiki-domain/graphql
mutation {
authentication {
resetGuestUser {
responseResult {
succeeded
message
}
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "mutation { authentication { resetGuestUser { responseResult { succeeded message } } } }"}' \
https://your-wiki-domain/graphql
query {
users {
list {
id
name
email
providerKey
isActive
createdAt
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "query { users { list { id name email providerKey isActive createdAt } } }"}' \
https://your-wiki-domain/graphql
query {
users {
search(query: "john") {
id
name
email
isActive
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "query { users { search(query: \"john\") { id name email isActive } } }"}' \
https://your-wiki-domain/graphql
query {
users {
single(id: 1) {
id
name
email
isActive
isVerified
location
jobTitle
timezone
dateFormat
providerKey
tfaIsActive
lastLoginAt
groups {
id
name
}
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "query { users { single(id: 1) { id name email isActive isVerified location jobTitle timezone dateFormat providerKey tfaIsActive lastLoginAt groups { id name } } } }"}' \
https://your-wiki-domain/graphql
query {
users {
profile {
id
name
email
location
jobTitle
timezone
dateFormat
appearance
groups
pagesTotal
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "query { users { profile { id name email location jobTitle timezone dateFormat appearance groups pagesTotal } } }"}' \
https://your-wiki-domain/graphql
query {
users {
lastLogins {
id
name
lastLoginAt
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "query { users { lastLogins { id name lastLoginAt } } }"}' \
https://your-wiki-domain/graphql
mutation {
users {
create(
email: "new.user@example.com"
name: "New User"
passwordRaw: "SecurePassword123"
providerKey: "local"
groups: [1, 2]
mustChangePassword: true
sendWelcomeEmail: true
) {
responseResult {
succeeded
message
}
user {
id
name
email
}
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "mutation { users { create(email: \"new.user@example.com\", name: \"New User\", passwordRaw: \"SecurePassword123\", providerKey: \"local\", groups: [1, 2], mustChangePassword: true, sendWelcomeEmail: true) { responseResult { succeeded message } user { id name email } } } }"}' \
https://your-wiki-domain/graphql
mutation {
users {
update(
id: 1
email: "updated.email@example.com"
name: "Updated Name"
groups: [1, 3, 5]
location: "北京"
jobTitle: "开发工程师"
timezone: "Asia/Shanghai"
dateFormat: "YYYY/MM/DD"
appearance: "dark"
) {
responseResult {
succeeded
message
}
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "mutation { users { update(id: 1, email: \"updated.email@example.com\", name: \"Updated Name\", groups: [1, 3, 5], location: \"北京\", jobTitle: \"开发工程师\", timezone: \"Asia/Shanghai\", dateFormat: \"YYYY/MM/DD\", appearance: \"dark\") { responseResult { succeeded message } } } }"}' \
https://your-wiki-domain/graphql
mutation {
users {
delete(
id: 5
replaceId: 1
) {
responseResult {
succeeded
message
}
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "mutation { users { delete(id: 5, replaceId: 1) { responseResult { succeeded message } } } }"}' \
https://your-wiki-domain/graphql
mutation {
users {
verify(id: 5) {
responseResult {
succeeded
message
}
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "mutation { users { verify(id: 5) { responseResult { succeeded message } } } }"}' \
https://your-wiki-domain/graphql
mutation {
users {
activate(id: 5) {
responseResult {
succeeded
message
}
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "mutation { users { activate(id: 5) { responseResult { succeeded message } } } }"}' \
https://your-wiki-domain/graphql
mutation {
users {
deactivate(id: 5) {
responseResult {
succeeded
message
}
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "mutation { users { deactivate(id: 5) { responseResult { succeeded message } } } }"}' \
https://your-wiki-domain/graphql
mutation {
users {
enableTFA(id: 5) {
responseResult {
succeeded
message
}
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "mutation { users { enableTFA(id: 5) { responseResult { succeeded message } } } }"}' \
https://your-wiki-domain/graphql
mutation {
users {
disableTFA(id: 5) {
responseResult {
succeeded
message
}
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "mutation { users { disableTFA(id: 5) { responseResult { succeeded message } } } }"}' \
https://your-wiki-domain/graphql
mutation {
users {
resetPassword(id: 5) {
responseResult {
succeeded
message
}
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "mutation { users { resetPassword(id: 5) { responseResult { succeeded message } } } }"}' \
https://your-wiki-domain/graphql
mutation {
users {
updateProfile(
name: "My Name"
location: "上海"
jobTitle: "产品经理"
timezone: "Asia/Shanghai"
dateFormat: "YYYY-MM-DD"
appearance: "light"
) {
responseResult {
succeeded
message
}
jwt
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "mutation { users { updateProfile(name: \"My Name\", location: \"上海\", jobTitle: \"产品经理\", timezone: \"Asia/Shanghai\", dateFormat: \"YYYY-MM-DD\", appearance: \"light\") { responseResult { succeeded message } jwt } } }"}' \
https://your-wiki-domain/graphql
mutation {
users {
changePassword(
current: "CurrentPassword123"
new: "NewPassword456"
) {
responseResult {
succeeded
message
}
jwt
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "mutation { users { changePassword(current: \"CurrentPassword123\", new: \"NewPassword456\") { responseResult { succeeded message } jwt } } }"}' \
https://your-wiki-domain/graphql
query {
pages {
list(
limit: 20
orderBy: UPDATED
orderByDirection: DESC
) {
id
path
title
description
updatedAt
createdAt
isPublished
tags
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "query { pages { list(limit: 20, orderBy: UPDATED, orderByDirection: DESC) { id path title description updatedAt createdAt isPublished tags } } }"}' \
https://your-wiki-domain/graphql
query {
pages {
single(id: 123) {
id
path
title
description
content
render
isPublished
updatedAt
tags {
id
tag
title
}
authorName
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "query { pages { single(id: 123) { id path title description content render isPublished updatedAt tags { id tag title } authorName } } }"}' \
https://your-wiki-domain/graphql
query {
pages {
singleByPath(
path: "/path/to/page"
locale: "zh"
) {
id
title
description
content
render
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "query { pages { singleByPath(path: \"/path/to/page\", locale: \"zh\") { id title description content render } } }"}' \
https://your-wiki-domain/graphql
query {
pages {
history(
id: 123
offsetPage: 0
offsetSize: 10
) {
total
trail {
versionId
versionDate
authorId
authorName
actionType
valueBefore
valueAfter
}
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "query { pages { history(id: 123, offsetPage: 0, offsetSize: 10) { total trail { versionId versionDate authorId authorName actionType valueBefore valueAfter } } } }"}' \
https://your-wiki-domain/graphql
query {
pages {
version(
pageId: 123
versionId: 5
) {
action
authorId
authorName
content
contentType
versionDate
description
title
path
tags
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "query { pages { version(pageId: 123, versionId: 5) { action authorId authorName content contentType versionDate description title path tags } } }"}' \
https://your-wiki-domain/graphql
query {
pages {
search(
query: "关键词"
path: "/folder"
locale: "zh"
) {
results {
id
title
description
path
locale
}
suggestions
totalHits
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "query { pages { search(query: \"关键词\", path: \"/folder\", locale: \"zh\") { results { id title description path locale } suggestions totalHits } } }"}' \
https://your-wiki-domain/graphql
query {
pages {
tags {
id
tag
title
createdAt
updatedAt
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "query { pages { tags { id tag title createdAt updatedAt } } }"}' \
https://your-wiki-domain/graphql
query {
pages {
searchTags(query: "doc")
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "query { pages { searchTags(query: \"doc\") } }"}' \
https://your-wiki-domain/graphql
query {
pages {
tree(
path: "/docs"
mode: ALL
locale: "zh"
includeAncestors: true
) {
id
path
depth
title
isPrivate
isFolder
pageId
locale
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "query { pages { tree(path: \"/docs\", mode: ALL, locale: \"zh\", includeAncestors: true) { id path depth title isPrivate isFolder pageId locale } } }"}' \
https://your-wiki-domain/graphql
query {
pages {
links(locale: "zh") {
id
path
title
links
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "query { pages { links(locale: \"zh\") { id path title links } } }"}' \
https://your-wiki-domain/graphql
query {
pages {
checkConflicts(
id: 123
checkoutDate: "2023-08-15T12:00:00Z"
)
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "query { pages { checkConflicts(id: 123, checkoutDate: \"2023-08-15T12:00:00Z\") } }"}' \
https://your-wiki-domain/graphql
query {
pages {
conflictLatest(id: 123) {
id
authorId
authorName
content
createdAt
updatedAt
description
title
path
tags
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "query { pages { conflictLatest(id: 123) { id authorId authorName content createdAt updatedAt description title path tags } } }"}' \
https://your-wiki-domain/graphql
mutation {
pages {
create(
content: "# Hello World\nThis is my new page content."
description: "A sample page description"
editor: "markdown"
isPublished: true
isPrivate: false
locale: "zh"
path: "/sample/new-page"
tags: ["sample", "documentation"]
title: "My New Page"
) {
responseResult {
succeeded
message
}
page {
id
path
}
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "mutation { pages { create(content: \"# Hello World\\nThis is my new page content.\", description: \"A sample page description\", editor: \"markdown\", isPublished: true, isPrivate: false, locale: \"zh\", path: \"/sample/new-page\", tags: [\"sample\", \"documentation\"], title: \"My New Page\") { responseResult { succeeded message } page { id path } } } }"}' \
https://your-wiki-domain/graphql
mutation {
pages {
update(
id: 123
content: "# Updated Content\nThis page has been updated."
description: "Updated description"
isPublished: true
tags: ["updated", "documentation"]
title: "Updated Page Title"
) {
responseResult {
succeeded
message
}
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "mutation { pages { update(id: 123, content: \"# Updated Content\\nThis page has been updated.\", description: \"Updated description\", isPublished: true, tags: [\"updated\", \"documentation\"], title: \"Updated Page Title\") { responseResult { succeeded message } } } }"}' \
https://your-wiki-domain/graphql
mutation {
pages {
convert(
id: 123
editor: "html"
) {
responseResult {
succeeded
message
}
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "mutation { pages { convert(id: 123, editor: \"html\") { responseResult { succeeded message } } } }"}' \
https://your-wiki-domain/graphql
mutation {
pages {
move(
id: 123
destinationPath: "/new/location"
destinationLocale: "zh"
) {
responseResult {
succeeded
message
}
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "mutation { pages { move(id: 123, destinationPath: \"/new/location\", destinationLocale: \"zh\") { responseResult { succeeded message } } } }"}' \
https://your-wiki-domain/graphql
mutation {
pages {
delete(id: 123) {
responseResult {
succeeded
message
}
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "mutation { pages { delete(id: 123) { responseResult { succeeded message } } } }"}' \
https://your-wiki-domain/graphql
mutation {
pages {
deleteTag(id: 45) {
responseResult {
succeeded
message
}
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "mutation { pages { deleteTag(id: 45) { responseResult { succeeded message } } } }"}' \
https://your-wiki-domain/graphql
mutation {
pages {
updateTag(
id: 45
tag: "documentation"
title: "文档"
) {
responseResult {
succeeded
message
}
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "mutation { pages { updateTag(id: 45, tag: \"documentation\", title: \"文档\") { responseResult { succeeded message } } } }"}' \
https://your-wiki-domain/graphql
mutation {
pages {
flushCache {
responseResult {
succeeded
message
}
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "mutation { pages { flushCache { responseResult { succeeded message } } } }"}' \
https://your-wiki-domain/graphql
mutation {
pages {
migrateToLocale(
sourceLocale: "en"
targetLocale: "zh"
) {
responseResult {
succeeded
message
}
count
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "mutation { pages { migrateToLocale(sourceLocale: \"en\", targetLocale: \"zh\") { responseResult { succeeded message } count } } }"}' \
https://your-wiki-domain/graphql
mutation {
pages {
rebuildTree {
responseResult {
succeeded
message
}
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "mutation { pages { rebuildTree { responseResult { succeeded message } } } }"}' \
https://your-wiki-domain/graphql
mutation {
pages {
render(id: 123) {
responseResult {
succeeded
message
}
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "mutation { pages { render(id: 123) { responseResult { succeeded message } } } }"}' \
https://your-wiki-domain/graphql
mutation {
pages {
restore(
pageId: 123
versionId: 5
) {
responseResult {
succeeded
message
}
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "mutation { pages { restore(pageId: 123, versionId: 5) { responseResult { succeeded message } } } }"}' \
https://your-wiki-domain/graphql
mutation {
pages {
purgeHistory(
olderThan: "30d"
) {
responseResult {
succeeded
message
}
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "mutation { pages { purgeHistory(olderThan: \"30d\") { responseResult { succeeded message } } } }"}' \
https://your-wiki-domain/graphql
query {
assets {
list(folderId: 0, kind: ALL) {
id
filename
ext
kind
mime
fileSize
createdAt
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "query { assets { list(folderId: 0, kind: ALL) { id filename ext kind mime fileSize createdAt } } }"}' \
https://your-wiki-domain/graphql
query {
assets {
folders(parentFolderId: 0) {
id
slug
name
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "query { assets { folders(parentFolderId: 0) { id slug name } } }"}' \
https://your-wiki-domain/graphql
mutation {
assets {
createFolder(
parentFolderId: 0
slug: "images"
name: "图片资源"
) {
responseResult {
succeeded
message
}
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "mutation { assets { createFolder(parentFolderId: 0, slug: \"images\", name: \"图片资源\") { responseResult { succeeded message } } } }"}' \
https://your-wiki-domain/graphql
mutation {
assets {
renameAsset(
id: 123
filename: "renamed-image.jpg"
) {
responseResult {
succeeded
message
}
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "mutation { assets { renameAsset(id: 123, filename: \"renamed-image.jpg\") { responseResult { succeeded message } } } }"}' \
https://your-wiki-domain/graphql
mutation {
assets {
deleteAsset(id: 123) {
responseResult {
succeeded
message
}
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "mutation { assets { deleteAsset(id: 123) { responseResult { succeeded message } } } }"}' \
https://your-wiki-domain/graphql
query {
navigation {
tree {
locale
items {
id
kind
label
icon
targetType
target
}
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "query { navigation { tree { locale items { id kind label icon targetType target } } } }"}' \
https://your-wiki-domain/graphql
mutation {
navigation {
updateTree(
tree: [
{
locale: "zh"
items: [
{
id: "home"
kind: "link"
label: "首页"
icon: "home"
targetType: "page"
target: "/"
visibilityMode: "all"
},
{
id: "docs"
kind: "link"
label: "文档"
icon: "book"
targetType: "page"
target: "/docs"
visibilityMode: "all"
}
]
}
]
) {
responseResult {
succeeded
message
}
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "mutation { navigation { updateTree(tree: [{locale: \"zh\", items: [{id: \"home\", kind: \"link\", label: \"首页\", icon: \"home\", targetType: \"page\", target: \"/\", visibilityMode: \"all\"}, {id: \"docs\", kind: \"link\", label: \"文档\", icon: \"book\", targetType: \"page\", target: \"/docs\", visibilityMode: \"all\"}]}]) { responseResult { succeeded message } } } }"}' \
https://your-wiki-domain/graphql
query {
groups {
list {
id
name
isSystem
userCount
createdAt
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "query { groups { list { id name isSystem userCount createdAt } } }"}' \
https://your-wiki-domain/graphql
query {
groups {
single(id: 1) {
id
name
permissions
pageRules {
id
deny
match
roles
path
locales
}
users {
id
name
email
}
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "query { groups { single(id: 1) { id name permissions pageRules { id deny match roles path locales } users { id name email } } } }"}' \
https://your-wiki-domain/graphql
mutation {
groups {
create(name: "编辑团队") {
responseResult {
succeeded
message
}
group {
id
name
}
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "mutation { groups { create(name: \"编辑团队\") { responseResult { succeeded message } group { id name } } } }"}' \
https://your-wiki-domain/graphql
mutation {
groups {
update(
id: 2
name: "高级编辑"
redirectOnLogin: "/dashboard"
permissions: ["read:pages", "write:pages", "manage:pages"]
pageRules: [
{
id: "rule1",
deny: false,
match: START,
roles: ["read:pages"],
path: "/docs",
locales: ["zh"]
},
{
id: "rule2",
deny: true,
match: REGEX,
roles: ["write:pages"],
path: "^/admin/.*$",
locales: ["zh", "en"]
}
]
) {
responseResult {
succeeded
message
}
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "mutation { groups { update(id: 2, name: \"高级编辑\", redirectOnLogin: \"/dashboard\", permissions: [\"read:pages\", \"write:pages\", \"manage:pages\"], pageRules: [{id: \"rule1\", deny: false, match: START, roles: [\"read:pages\"], path: \"/docs\", locales: [\"zh\"]}, {id: \"rule2\", deny: true, match: REGEX, roles: [\"write:pages\"], path: \"^/admin/.*$\", locales: [\"zh\", \"en\"]}]) { responseResult { succeeded message } } } }"}' \
https://your-wiki-domain/graphql
mutation {
groups {
assignUser(
groupId: 2
userId: 5
) {
responseResult {
succeeded
message
}
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "mutation { groups { assignUser(groupId: 2, userId: 5) { responseResult { succeeded message } } } }"}' \
https://your-wiki-domain/graphql
mutation {
groups {
unassignUser(
groupId: 2
userId: 5
) {
responseResult {
succeeded
message
}
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "mutation { groups { unassignUser(groupId: 2, userId: 5) { responseResult { succeeded message } } } }"}' \
https://your-wiki-domain/graphql
mutation {
groups {
delete(id: 3) {
responseResult {
succeeded
message
}
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "mutation { groups { delete(id: 3) { responseResult { succeeded message } } } }"}' \
https://your-wiki-domain/graphql
WikiJS的权限系统基于用户组和权限规则。下面介绍一些核心权限相关的操作:
您可以通过查询单个群组来查看其拥有的权限:
query {
groups {
single(id: 1) {
permissions
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "query { groups { single(id: 1) { permissions } } }"}' \
https://your-wiki-domain/graphql
在更新用户组时,您可以设置该组的权限:
mutation {
groups {
update(
id: 2
name: "内容编辑"
permissions: [
"read:pages",
"write:pages",
"manage:pages",
"read:assets",
"upload:assets"
]
pageRules: []
) {
responseResult {
succeeded
}
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "mutation { groups { update(id: 2, name: \"内容编辑\", permissions: [\"read:pages\", \"write:pages\", \"manage:pages\", \"read:assets\", \"upload:assets\"], pageRules: []) { responseResult { succeeded } } } }"}' \
https://your-wiki-domain/graphql
页面规则允许您为特定路径和语言设置详细的访问控制:
mutation {
groups {
update(
id: 2
pageRules: [
{
id: "confidential",
deny: true,
match: START,
roles: ["read:pages"],
path: "/confidential",
locales: ["zh", "en"]
},
{
id: "projects",
deny: false,
match: REGEX,
roles: ["write:pages"],
path: "^/projects/.*$",
locales: ["zh"]
}
]
) {
responseResult {
succeeded
message
}
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "mutation { groups { update(id: 2, pageRules: [{id: \"confidential\", deny: true, match: START, roles: [\"read:pages\"], path: \"/confidential\", locales: [\"zh\", \"en\"]}, {id: \"projects\", deny: false, match: REGEX, roles: [\"write:pages\"], path: \"^/projects/.*$\", locales: [\"zh\"]}]) { responseResult { succeeded message } } } }"}' \
https://your-wiki-domain/graphql
页面规则的match属性支持以下匹配模式:
START: 匹配以指定路径开头的页面EXACT: 精确匹配指定路径的页面END: 匹配以指定路径结尾的页面REGEX: 使用正则表达式匹配路径TAG: 匹配包含指定标签的页面query {
comments {
providers {
key
title
isEnabled
description
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "query { comments { providers { key title isEnabled description } } }"}' \
https://your-wiki-domain/graphql
query {
comments {
list(
locale: "zh"
path: "/path/to/page"
) {
id
content
render
authorName
createdAt
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "query { comments { list(locale: \"zh\", path: \"/path/to/page\") { id content render authorName createdAt } } }"}' \
https://your-wiki-domain/graphql
mutation {
comments {
create(
pageId: 123
content: "这是一条评论内容。"
) {
responseResult {
succeeded
message
}
id
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "mutation { comments { create(pageId: 123, content: \"这是一条评论内容。\") { responseResult { succeeded message } id } } }"}' \
https://your-wiki-domain/graphql
query {
localization {
locales {
code
name
nativeName
isInstalled
isRTL
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "query { localization { locales { code name nativeName isInstalled isRTL } } }"}' \
https://your-wiki-domain/graphql
query {
localization {
config {
locale
autoUpdate
namespacing
namespaces
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "query { localization { config { locale autoUpdate namespacing namespaces } } }"}' \
https://your-wiki-domain/graphql
query {
localization {
translations(
locale: "zh"
namespace: "common"
) {
key
value
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "query { localization { translations(locale: \"zh\", namespace: \"common\") { key value } } }"}' \
https://your-wiki-domain/graphql
query {
analytics {
providers(isEnabled: true) {
isEnabled
key
title
description
isAvailable
website
config {
key
value
}
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "query { analytics { providers(isEnabled: true) { isEnabled key title description isAvailable website config { key value } } } }"}' \
https://your-wiki-domain/graphql
mutation {
analytics {
updateProviders(
providers: [
{
isEnabled: true
key: "google"
config: [
{
key: "trackingId"
value: "UA-XXXXXXXX-X"
}
]
}
]
) {
responseResult {
succeeded
message
}
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "mutation { analytics { updateProviders(providers: [{isEnabled: true, key: \"google\", config: [{key: \"trackingId\", value: \"UA-XXXXXXXX-X\"}]}]) { responseResult { succeeded message } } } }"}' \
https://your-wiki-domain/graphql
query {
contribute {
contributors {
id
source
name
joined
website
twitter
avatar
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "query { contribute { contributors { id source name joined website twitter avatar } } }"}' \
https://your-wiki-domain/graphql
query {
logging {
loggers {
isEnabled
key
title
description
level
config {
key
value
}
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "query { logging { loggers { isEnabled key title description level config { key value } } } }"}' \
https://your-wiki-domain/graphql
mutation {
logging {
updateLoggers(
loggers: [
{
isEnabled: true
key: "console"
level: "info"
config: []
}
]
) {
responseResult {
succeeded
message
}
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "mutation { logging { updateLoggers(loggers: [{isEnabled: true, key: \"console\", level: \"info\", config: []}]) { responseResult { succeeded message } } } }"}' \
https://your-wiki-domain/graphql
WikiJS支持通过WebSocket订阅实时日志:
subscription {
loggingLiveTrail {
level
output
timestamp
}
}
注意: 订阅查询不能通过curl直接执行,需要使用支持WebSocket的GraphQL客户端。
query {
mail {
config {
senderName
senderEmail
host
port
name
secure
verifySSL
useDKIM
dkimDomainName
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "query { mail { config { senderName senderEmail host port name secure verifySSL useDKIM dkimDomainName } } }"}' \
https://your-wiki-domain/graphql
mutation {
mail {
sendTest(
recipientEmail: "test@example.com"
) {
responseResult {
succeeded
message
}
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "mutation { mail { sendTest(recipientEmail: \"test@example.com\") { responseResult { succeeded message } } } }"}' \
https://your-wiki-domain/graphql
mutation {
mail {
updateConfig(
senderName: "WikiJS"
senderEmail: "wiki@example.com"
host: "smtp.example.com"
port: 587
name: "wiki-smtp"
secure: true
verifySSL: true
user: "smtp-user"
pass: "smtp-password"
useDKIM: false
dkimDomainName: ""
dkimKeySelector: ""
dkimPrivateKey: ""
) {
responseResult {
succeeded
message
}
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "mutation { mail { updateConfig(senderName: \"WikiJS\", senderEmail: \"wiki@example.com\", host: \"smtp.example.com\", port: 587, name: \"wiki-smtp\", secure: true, verifySSL: true, user: \"smtp-user\", pass: \"smtp-password\", useDKIM: false, dkimDomainName: \"\", dkimKeySelector: \"\", dkimPrivateKey: \"\") { responseResult { succeeded message } } } }"}' \
https://your-wiki-domain/graphql
query {
rendering {
renderers {
isEnabled
key
title
description
icon
dependsOn
input
output
config {
key
value
}
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "query { rendering { renderers { isEnabled key title description icon dependsOn input output config { key value } } } }"}' \
https://your-wiki-domain/graphql
mutation {
rendering {
updateRenderers(
renderers: [
{
isEnabled: true
key: "markdown"
config: [
{
key: "mathjax"
value: "true"
}
]
}
]
) {
responseResult {
succeeded
message
}
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "mutation { rendering { updateRenderers(renderers: [{isEnabled: true, key: \"markdown\", config: [{key: \"mathjax\", value: \"true\"}]}]) { responseResult { succeeded message } } } }"}' \
https://your-wiki-domain/graphql
query {
storage {
targets {
isEnabled
key
title
description
isAvailable
mode
hasSchedule
syncInterval
config {
key
value
}
actions {
handler
label
hint
}
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "query { storage { targets { isEnabled key title description isAvailable mode hasSchedule syncInterval config { key value } actions { handler label hint } } } }"}' \
https://your-wiki-domain/graphql
query {
storage {
status {
key
title
status
message
lastAttempt
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "query { storage { status { key title status message lastAttempt } } }"}' \
https://your-wiki-domain/graphql
mutation {
storage {
updateTargets(
targets: [
{
isEnabled: true
key: "git"
mode: "sync"
syncInterval: "PT1H"
config: [
{
key: "repoUrl"
value: "https://github.com/your-username/your-repo.git"
},
{
key: "branch"
value: "main"
}
]
}
]
) {
responseResult {
succeeded
message
}
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "mutation { storage { updateTargets(targets: [{isEnabled: true, key: \"git\", mode: \"sync\", syncInterval: \"PT1H\", config: [{key: \"repoUrl\", value: \"https://github.com/your-username/your-repo.git\"}, {key: \"branch\", value: \"main\"}]}]) { responseResult { succeeded message } } } }"}' \
https://your-wiki-domain/graphql
mutation {
storage {
executeAction(
targetKey: "git"
handler: "syncNow"
) {
responseResult {
succeeded
message
}
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "mutation { storage { executeAction(targetKey:
### 站点配置
```graphql
query {
site {
config {
title
description
host
company
contentLicense
logoUrl
featurePageComments
featurePageRatings
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "query { site { config { title description host company contentLicense logoUrl featurePageComments featurePageRatings } } }"}' \
https://your-wiki-domain/graphql
mutation {
site {
updateConfig(
title: "我的知识库"
description: "团队协作知识管理系统"
company: "我的公司"
featurePageComments: true
featurePageRatings: true
) {
responseResult {
succeeded
message
}
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "mutation { site { updateConfig(title: \"我的知识库\", description: \"团队协作知识管理系统\", company: \"我的公司\", featurePageComments: true, featurePageRatings: true) { responseResult { succeeded message } } } }"}' \
https://your-wiki-domain/graphql
query {
theming {
themes {
key
title
author
}
config {
theme
darkMode
iconset
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "query { theming { themes { key title author } config { theme darkMode iconset } } }"}' \
https://your-wiki-domain/graphql
mutation {
theming {
setConfig(
theme: "default"
iconset: "material-icons"
darkMode: true
) {
responseResult {
succeeded
message
}
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "mutation { theming { setConfig(theme: \"default\", iconset: \"material-icons\", darkMode: true) { responseResult { succeeded message } } } }"}' \
https://your-wiki-domain/graphql
query {
search {
searchEngines {
key
title
isEnabled
description
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "query { search { searchEngines { key title isEnabled description } } }"}' \
https://your-wiki-domain/graphql
query {
pages {
search(
query: "wiki"
locale: "zh"
) {
results {
id
title
description
path
locale
}
totalHits
}
}
}
curl示例:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"query": "query { pages { search(query: \"wiki\", locale: \"zh\") { results { id title description path locale } totalHits } } }"}' \
https://your-wiki-domain/graphql