🖥

Gtihub API の webhook 作成でエラー ( Resource not accessible by personal acce

2023/09/01に公開

コマンド例とエラー

curl -L \
  -X POST \
  -H "Accept: application/vnd.github+json" \
  -H "Authorization: Bearer github_pat_1xxxxxxxxxxxxxxxxxxxxxxxx"\
  -H "X-GitHub-Api-Version: 2022-11-28" \
  https://api.github.com/repos/[OWNER]/[REPOSITORY]/hooks \
  -d '{"name":"web","active":true,"events":["push","pull_request"],"config":{"url":"https://example.com/webhook","content_type":"json","insecure_ssl":"0"}}'

publicレポジトリの場合のエラー

{
  "message": "Resource not accessible by personal access token",
  "documentation_url": "https://docs.github.com/rest/webhooks/repos#create-a-repository-webhook"
}

privateレポジトリの場合のエラー

{
  "message": "Not Found",
  "documentation_url": "https://docs.github.com/rest/webhooks/repos#create-a-repository-webhook"
}

解決 - fine-grained personal access token

fine-grained personal access token を作成する時にパーミッションを許可することでWebHookが作成可能になった

https://github.com/settings/personal-access-tokens/new

image

<img width="935" alt="image" src="https://user-images.githubusercontent.com/13635059/229003726-51500b14-a78e-4e4e-8bf2-2c61ad3ba2cc.png">

personal access token (classic)

personal access token (classic) の場合は write:repo_hook を有効にすれば良いようだ

<img width="612" alt="image" src="https://user-images.githubusercontent.com/13635059/229012031-4b6b871e-56f7-4c2a-a701-5c2937af0aa0.png">

https://github.com/settings/personal-access-tokens/new

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

https://line.me/ti/g2/eEPltQ6Tzh3pYAZV8JXKZqc7PJ6L0rpm573dcQ

Twitter

https://twitter.com/YumaInaura

公開日時

2023-03-31

Discussion