List org members via Github App #190354
Replies: 3 comments 4 replies
-
|
The issue is not your query structure. The problem is authentication context when switching from a PAT to a GitHub App. With a GitHub App, viewer is the app installation, not a user. That breaks access to fields like:
|
Beta Was this translation helpful? Give feedback.
-
|
Hi there! 👋 Yes, there absolutely is a query for this! You are very close, but the key difference lies in how GitHub's GraphQL API handles the When you use a Personal Access Token (PAT), the To fix this, you simply need to drop the 1. The Corrected GraphQL QueryHere is the exact query you need. I have also removed query ListOrganizationMembers($org: String!, $cursor: String, $first: Int = 100) {
organization(login: $org) {
membersWithRole(after: $cursor, first: $first) {
totalCount
edges {
hasTwoFactorEnabled
role
node {
databaseId
login
name
id
email
twitterUsername
url
bio
bioHTML
location
company
companyHTML
isBountyHunter
isHireable
isEmployee
isSiteAdmin
isGitHubStar
isCampusExpert
isDeveloperProgramMember
hasSponsorsListing
followers { totalCount }
following { totalCount }
gists { totalCount }
repositories { totalCount }
watching { totalCount }
estimatedNextSponsorsPayoutInCents
monthlyEstimatedSponsorsIncomeInCents
websiteUrl
createdAt
updatedAt
}
}
pageInfo {
endCursor
hasNextPage
}
}
}
}2. Verify Your GitHub App PermissionsBecause GitHub Apps rely on strict, granular permissions rather than inheriting user access, you must ensure your App is explicitly allowed to read organization members.
3. Authenticating with Octokit in TypeScriptSince you mentioned using Octokit in TS, make sure you are executing the GraphQL query using an installation token, not the App's JWT. Here is the standard implementation: import { App } from "octokit";
// 1. Initialize the App
const app = new App({
appId: process.env.APP_ID,
privateKey: process.env.PRIVATE_KEY,
});
// 2. Get the authenticated Octokit client for the specific installation
const octokit = await app.getInstallationOctokit(YOUR_INSTALLATION_ID);
// 3. Execute your GraphQL query
const response = await octokit.graphql(YOUR_QUERY, {
org: "your-org-name"
});Let me know if this gets your member list fetching correctly! |
Beta Was this translation helpful? Give feedback.
-
|
Use this: For GitHub App authentication, Query the organization directly instead: query ListOrganizationMembers($org: String!, $cursor: String, $first: Int = 100) {
organization(login: $org) {
membersWithRole(first: $first, after: $cursor) {
totalCount
edges {
role
node {
id
login
name
url
}
}
pageInfo {
endCursor
hasNextPage
}
}
}
}Also make sure the GitHub App is installed on that org and has the required Members organization permission. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Select Topic Area
Question
Body
I was using PAT for authentication and below GraphQL query to fetch org members. Now, I want to support auth via github apps as well, but this query doesn't provide the expected response. what is the correct query to fetch org members with github app authentication. I am using Ocktokit in ts for generating token
Beta Was this translation helpful? Give feedback.
All reactions