Skip to main content

Overview

GitHub allows you to create two kinds of webhooks.
  1. Organization Webhooks : These are webhooks that are created at the organization level. They are triggered by events that happen in the organization.
  2. Repository Webhooks : These are webhooks that are created at the repository level. They are triggered by events that happen in the repository.

GitHub API Quirks

Every GitHub REST API request for creating a webhook requires a minimum of either an organization or a combination of an organization and a repository. We provider two usefull hooks to help you get the organization and repository values for your users. See the below example on how to create a webhook for your user.

Creating a Webhook for a User using the SDK

  1. Get a list of your users Organizations with useGetGitHubOrganizations: This hook returns a list of organizations that the user is a part of based off of their GitHub access token. You can get this access token from your third party provider like Nango.
    create-GitHub.ts
  2. (OPTIONAL) Get a list of your users Repositories with useGetGitHubReposForOrganization: If you want to listen to a specific repository and not just the overarching Organization, this hook returns a list of repositories that the user is a part of based off of their GitHub access token and the organization they chose in the previous step. Don’t worry about the organization name not being selected yet, the repo hook handles the retry logic for you.
    create-GitHub.ts
  3. Create a new webhook with all the information we gatherd from our user in the previous steps.
create-GitHub.ts

Updating a Webhook for a User

If you want you can update an existing webhook to listen to new events, update callback endpoints, and more. The resulting webhook will be under the same project and endpointId so you don’t need to worry about updating things in your database/storage. This would look something like this:

Example Payloads

With each provider we have example payloads so you can test the webhook events. This can be useful for debugging and testing your application. To import, each payload example starts with the provider name and then the event name. For example, figmaFileCommentEventExamplePayload. Use intelligent auto-complete in your IDE to find the payload you need. Here is an example payload for branch_protection_rule:

Types

In the background for GitHub we use Octoit for all our types. You can find a list of all the types and requests in the GitHub provider here: GitHub Types

Seeing logs and webhook bodies

To view logs or webhook bodies for debugging, you can use the Dashboard. If you messed up the callback URL endpoint you can change it here. You can go to the dashboard here: Syncd.