进阶 docs.stashapp.cc 2026-10-20 02:59:21 · 19 阅读

第3章 Stash GraphQL API 使用指南与身份验证

Stash GraphQL API¶ Stash 的 GraphQL API 通过基于类型的 schema 支持自动化操作,这种 schema 既支持内省,又是自文档化的。 Stash 内置了一个 playground,用户可以在其中执行查询,并通过特殊的内省查询获取 schema 结构和文档。

了解更多 GraphQL 相关知识 更多信息请访问 GraphQL 官方网站。

访问 GraphQL playground¶

导航到 Settings > Tools > GraphQL playground。 点击左侧的 打开 Documentation Explorer。

Endpoint¶ 所有 HTTP 请求都应发送到 :/graphql(默认为 localhost:9999/graphql)。 身份验证¶ 每次请求都需在 header 中附带 Stash 中生成的 API key。关于如何获取 API Key,请参考 Stash 应用内手册。 curl 示例

curl -X POST -H "ApiKey: " -H "Content-Type: application/json" --data '{ "query": "" }' localhost:9999/graphql

把 替换为你在 Settings > Security > Authentication 下找到的 API Key。 把 替换为原始查询,可在 playground 中生成格式化的查询。 旧版 cookie 身份验证¶

注意 此方式在 v0.7 版本中已被弃用,建议改用 API Key 方式。

对于使用用户名/密码的配置,需要通过 cookie 进行身份验证。 curl 示例

curl --verbose --cookie-jar cookie.txt --data 'username=stash&password=' localhost:9999/login curl --cookie cookie.txt -H "Content-Type: application/json" --data '{ "query": "" }' localhost:9999/graphql

评论 (0)