Search code examples
graphqlgithub-cli

Cannot list projectsV2 with GitHub Cli due to missing scopes


When running a GraphQL query with the GitHub CLI that uses the projectsV2, I get an error complaining about missing scopes:

Your token has not been granted the required scopes to execute this query. The 'projectsV2' field requires one of the following scopes: ['read:project'], but your token has only been granted the: ['admin:public_key', 'gist', 'read:org', 'repo'] scopes. Please modify your token's scopes at: https://github.com/settings/tokens.

Sample Query:

> gh api graphql -f query='{
  organization(login: "MyOrg") {
    projectsV2(last: 20) {
      nodes {
        title
      }
    }
  }
}'

How can I elevate the permissions of GitHub's CLI?


Solution

  • By default, GitHub's CLI only requests a few scopes when authenticating via gh auth login. However, the new projectsV2 requires read:project as well.

    This can be solved by requesting an additional scope during login, like so:

    > gh auth login --scopes read:project
    

    Or, if you also need to write to projects, you might even need full access to projects, like so:

    > gh auth login --scopes project
    

    Note that you might need to logout first: gh auth logout