GitHub API WebHooks returning 404 (unauthorized)
Hi everybody!
My users connect to GitHub with socialite and one thing I (want to) use that for is setting up a web hook for push events on repositories.
I'm asking for the scope (and getting it): GithubLoginController.php
public function redirectToProvider()
{
return Socialite::driver('github')
->scopes(['repo', 'admin:repo_hook'])
->redirect();
}
Then try to set up the hook:
GitHubClient.php
use GuzzleHttp\Client;
use Illuminate\Support\Facades\Auth;
class GithubClient
{
protected $client = null;
protected $endpoint = 'https://api.github.com';
public function __construct()
{
$this->client = new Client([
'base_uri' => $this->endpoint,
'headers' => [
'Authorization' => auth()->user()->github()->acces_token,
],
]);
}
public function post($path, $payload)
{
$ret = $this->client->post($path, [
'json' => $payload,
]);
return json_decode($ret->getBody());
}
public function createWebhook($username, $updateable)
{
$payload = [
'name' => 'web',
'config' => [
'url' => route('webhooks.github.payload', ['updateable' => $updateable]),
'content_type' => 'json',
],
];
return $this->post("/repos/{$username}/{$updateable->repository}/hooks", $payload);
}
But I get this error:
Client error: POST https://api.github.com/repos/melker-io/test/hooks resulted in a 404 Not Found response: { "message": "Not Found", "documentation_url": "https://developer.github.com/v3/repos/hooks/#create-a-hook" }
On GitHub a 404 like this means unauthorized - but I think I've got the correct scope? I've tried a few different scopes (write:repo_hook) but can't get it to work.
Anyone know what I'm doing wrong?
Please or to participate in this conversation.