Contentful Webhook无法触发GitHub Action及API 404问题排查
问题
我想通过Contentful Webhook触发GitHub Action,目前已完成以下配置:
- 配置了Contentful Webhook
- 编写了如下GitHub Action工作流:
name: Deploy # Run the workflow when a Contentful webhook is triggered on: repository_dispatch: types: [contentful.deploy] jobs: web-deploy: runs-on: ubuntu-latest
但在CMS中修改内容后没有任何反应,手动调用GitHub的repository_dispatch API(https://api.github.com/repos/{owner}/{repo}/dispatches)时,返回错误:
{ "message": "Not Found", "documentation_url": "https://docs.github.com/rest" }
仓库为公开状态,我已生成包含workflow、write:packages、admin:public_key、admin:repo_hook权限的Personal Access Token(PAT),请问问题出在哪里?
排查方向与解决方案
- API路径占位符未替换:调用
repository_dispatchAPI时,必须把路径中的{owner}和{repo}替换为实际的GitHub用户名/组织名、仓库名称,比如https://api.github.com/repos/octocat/hello-world/dispatches,未替换会直接返回404。 - PAT配置错误:确认PAT属于仓库拥有者/具备写入权限的用户,且调用API时请求头正确携带
Authorization: token <你的PAT>,无拼写错误。 - Contentful Webhook请求配置有误:检查Webhook的请求URL是否已替换占位符、请求方法是否为
POST、请求体是否包含event_type: contentful.deploy(需和Action工作流中types值完全一致)、是否正确添加了Authorization请求头。 - 工作流无执行步骤:当前工作流仅定义了运行环境,无实际执行逻辑,即使触发成功也无输出。可添加测试步骤验证触发状态:
jobs: web-deploy: runs-on: ubuntu-latest steps: - name: Test trigger run: echo "Workflow triggered successfully!"
内容的提问来源于stack exchange,提问作者Wookie
相关产品推荐
相关产品推荐

