Back

GitHub Issues API Essential Guide

Aug 9, 20246 minute read

What type of API does GitHub Issues provide?

Based on the search results, GitHub Issues offers both REST and GraphQL APIs:

  1. REST API: GitHub has a REST API that allows developers to interact with GitHub resources, including issues. The REST API provides endpoints for viewing, creating, editing, and managing issues.

  2. GraphQL API: GitHub also offers a GraphQL API, which is described as the latest version of GitHub's API. The GraphQL API provides more flexibility and efficiency in querying data compared to the REST API.

Key points to consider:

  • GitHub provides both REST and GraphQL APIs, giving developers options for how they want to interact with GitHub resources.
  • The REST API is well-established and follows RESTful principles, making it familiar to many developers.
  • The GraphQL API offers advantages such as more efficient data fetching, reduced over-fetching, and the ability to request exactly the data needed in a single query.
  • GraphQL is growing in popularity, and GitHub's adoption of it for their latest API version demonstrates its increasing importance in the API landscape.

Best practices:

  • Choose the API type that best fits your specific use case and development needs.
  • Consider using the GraphQL API for more complex queries or when you need to fetch data from multiple resources efficiently.
  • Use the REST API for simpler operations or if you prefer a more traditional API approach.
  • Familiarize yourself with both API types to take full advantage of GitHub's capabilities.

In summary, GitHub Issues supports both REST and GraphQL APIs, providing developers with flexibility in how they interact with the platform's resources.

Does the GitHub Issues API have webhooks?

Yes, the official GitHub Issues API does have webhooks. Here are the key points about GitHub Issues webhooks:

Webhook Support

GitHub provides webhook support for issues and many other events related to repositories, organizations, and GitHub Apps.

Event Types

You can subscribe to various event types related to issues, including:

  • issues - This event is triggered for various issue-related activities like opening, closing, assigning, labeling, etc.
  • issue_comment - This event is triggered when a comment is added, edited, or deleted on an issue or pull request
  • label - This event is triggered when a label is created, edited, or deleted
  • milestone - This event is triggered when a milestone is created, closed, opened, edited, or deleted

While not strictly issue events, there are other related events you can subscribe to:

  • project_card - For project board activities related to issues
  • project - For project-level activities that may involve issues
  • pull_request - For pull request activities (pull requests are a type of issue in GitHub)

Configuring Webhooks

You can configure webhooks at the repository or organization level:

  1. For repository-level webhooks:

    • Go to repository Settings > Webhooks
    • Click "Add webhook" to create a new one or edit existing ones
  2. For organization-level webhooks:

    • Go to organization Settings > Webhooks

Payload Information

When an event occurs, GitHub sends a POST request to the configured webhook URL with details about the event in the payload. The payload includes information such as:

  • The type of action that triggered the event (e.g., "opened", "closed", "edited")
  • Details about the issue or related object
  • Information about the repository and organization (if applicable)
  • The user who triggered the event

Best Practices

  • Choose the specific events you need to subscribe to rather than subscribing to all events.
  • Secure your webhook endpoint and validate the payload signature to ensure it's coming from GitHub.
  • Handle webhook deliveries asynchronously to avoid blocking the response to GitHub.

By using webhooks, you can create integrations that react in real-time to changes in issues and other GitHub objects, allowing for powerful automation and workflow enhancements.

Rate Limits and other limitations

The GitHub Issues API, as part of the GitHub REST API, has the following rate limits:

Primary Rate Limits

  1. For authenticated users:

    • 5,000 requests per hour per user [1][4]
    • This includes requests made with personal access tokens and requests made by GitHub Apps or OAuth apps on behalf of an authenticated user [1]
  2. For GitHub App installations:

    • 5,000 requests per hour per installation (minimum) [1]
    • For installations not on a GitHub Enterprise Cloud organization:
      • Additional 50 requests per hour for each repository beyond 20 repositories
      • Additional 50 requests per hour for each user beyond 20 users in an organization
      • Maximum limit of 12,500 requests per hour [1]
    • For installations on a GitHub Enterprise Cloud organization:
      • 15,000 requests per hour [1]
  3. For OAuth apps:

    • 5,000 requests per hour when using client ID and client secret for public data [5]
    • 10,000 requests per hour if the app is owned by a GitHub Enterprise Cloud organization [5]
  4. For GITHUB_TOKEN in GitHub Actions workflows:

    • 1,000 requests per hour per repository
    • 15,000 requests per hour per repository for resources belonging to a GitHub Enterprise Cloud account [1]

Secondary Rate Limits

In addition to primary rate limits, GitHub enforces secondary rate limits to prevent abuse and ensure API availability [1]:

  1. Concurrent requests: No more than 100 concurrent requests across REST and GraphQL APIs [1]

  2. Requests to a single endpoint:

    • No more than 900 points per minute for REST API endpoints [1]
    • No more than 2,000 points per minute for the GraphQL API endpoint [1]
  3. CPU time usage:

    • No more than 90 seconds of CPU time per 60 seconds of real time [1]
    • No more than 60 seconds of this CPU time may be for the GraphQL API [1]
  4. Content creation:

    • Generally, no more than 80 content-generating requests per minute [1]
    • No more than 500 content-generating requests per hour [1]

Key Points to Consider

  • Rate limits are subject to change without notice [1]
  • Rate limit information is available in each returned HTTP header of an API request [4]
  • Secondary rate limits refresh quickly, so you can wait until the limit resets by checking the response header [4]
  • Upgrading to GitHub Enterprise Cloud can provide higher rate limits for GitHub Apps and OAuth apps [1]

Best Practices

  1. Use authenticated requests instead of unauthenticated ones for higher rate limits [1]
  2. Consider using GitHub Apps for automation in organizations, as their rate limits scale with the number of repositories and users [1]
  3. Monitor rate limit information in API response headers to avoid hitting limits [4]
  4. Implement proper error handling and backoff strategies when encountering rate limit errors

By understanding and adhering to these rate limits, you can effectively use the GitHub Issues API while avoiding disruptions due to exceeding the allowed request quotas.

Latest API Version

The most recent version of the GitHub Issues API is part of the overall GitHub REST API, which is currently versioned as 2022-11-28. Here are the key points to consider:

API Version

  1. The current API version is 2022-11-28, released on November 28, 2022 [2].

  2. This version applies to all endpoints in the GitHub REST API, including those related to Issues [2].

Specifying the API Version

  1. To use the most recent version, you should include the X-GitHub-Api-Version header in your API requests [2].

  2. Example of specifying the API version in a curl request:

curl --header "X-GitHub-Api-Version:2022-11-28" https://api.github.com/zen

Key Points to Consider

  1. If you don't specify an API version, requests will default to using the 2022-11-28 version [2].

  2. GitHub's REST API considers every pull request an issue, but not every issue is a pull request. This means that "Issues" endpoints may return both issues and pull requests in the response [3].

  3. The API supports custom media types for different response formats, such as raw markdown, text-only, HTML, or full representations [3].

Best Practices

  1. Always specify the API version in your requests to ensure consistency and avoid potential breaking changes in future updates [2].

  2. When working with issues, be aware of the distinction between issues and pull requests in the API responses [3].

  3. Use appropriate query parameters (e.g., filter, state, labels) to narrow down your results when listing issues [3].

  4. Utilize pagination parameters (per_page and page) to manage large result sets efficiently [3].

By following these guidelines and using the most recent API version, you can ensure that your integrations with the GitHub Issues API are up-to-date and functioning correctly.

How to get a GitHub Issues developer account and API Keys?

1. Create a GitHub account

If you don't already have one, sign up for a free GitHub account at github.com.

2. Join the GitHub Developer Program

To get access to the GitHub API and developer features:

  • Go to the GitHub Developer Program page (https://developer.github.com/program/)
  • Click "Join the GitHub Developer Program"
  • Accept the terms and conditions

3. Create a GitHub App or Personal Access Token

You have two main options for authenticating with the GitHub API:

  1. Create a GitHub App:

    • Go to your GitHub account settings
    • Select "Developer settings" > "GitHub Apps"
    • Click "New GitHub App"
    • Configure permissions for Issues API access
  2. Generate a Personal Access Token:

    • Go to your GitHub account settings
    • Select "Developer settings" > "Personal access tokens"
    • Click "Generate new token"
    • Select the "repo" scope to access Issues

4. Make API requests

Once you have authentication set up, you can start making requests to the GitHub Issues API endpoints:

import requests url = "https://api.github.com/repos/{owner}/{repo}/issues" headers = { "Authorization": "token YOUR_ACCESS_TOKEN", "Accept": "application/vnd.github.v3+json" } response = requests.get(url, headers=headers)

What can you do with the GitHub Issues API?

Based on the search results, here are the key data models you can interact with using the GitHub Issues API:

Issues

  • Create, update, delete, and retrieve issues
  • Get a list of issues for a repository
  • Search for issues across repositories
  • Add and remove labels on issues
  • Add and remove assignees
  • Lock and unlock issues
  • Transfer issues between repositories

Comments

  • Create, update, delete, and retrieve issue comments
  • List comments on an issue

Labels

  • Create, update, delete, and retrieve labels
  • Add and remove labels from issues

Milestones

  • Create, update, delete, and retrieve milestones
  • Associate issues with milestones

Events

  • Retrieve issue events (e.g. labeled, assigned, etc.)

Assignees

  • Add and remove assignees from issues
  • List assignees for a repository

Reactions

  • Create and delete reactions on issues and comments

Projects

  • Associate issues with projects and project columns

Timeline

  • Retrieve the timeline of events for an issue

The API allows you to perform CRUD operations on these data models, as well as search and filter issues across repositories. You can also interact with related data like comments, labels, milestones, etc. associated with issues.