Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

projects returning empty. #1117

Open
bymem opened this issue May 19, 2023 · 1 comment
Open

projects returning empty. #1117

bymem opened this issue May 19, 2023 · 1 comment

Comments

@bymem
Copy link

bymem commented May 19, 2023

Hi

i'm trying to get all projects on our organisation or a repo but no matter which i tries out it just returns a empty array.
The repo is a private one, but have both made a classic token and a fined grained one. the closes i have come is getting a "Resource not accessible by personal access token" error.

So my code looks like this

require_once __DIR__ . '/vendor/autoload.php';

$client = new \Github\Client();
$client->authenticate('github_pat_[TOKEN]', null, Github\AuthMethod::ACCESS_TOKEN);
$repositories = $client->api('organizations')->repositories('NOVA-Intergalactic');

$projects = $client->api('org_projects')->all('NOVA-Intergalactic');
// $projects = $client->api('repo')->projects()->all('NOVA-Intergalactic', 'NovaAi');

echo '<pre>';
print_r($projects);
echo '</pre>';

The $repositories command does fetch the private repos, so i belive the token does have access to the private repos.

but $projects = $client->api('org_projects')->all('NOVA-Intergalactic'); Just returns a blank array

I have also tried out $projects = $client->api('repo')->projects()->all('NOVA-Intergalactic', 'NovaAi');But that throws the error "Resource not accessible by personal access token"

So i'm a little unsure on where to proceed.

@haridarshan
Copy link
Contributor

haridarshan commented May 23, 2023

That's because org_projects uses Projects (Classic) GitHub Rest Endpoint which doesn't return ProjectsV2 and are only accessible through Graphql.

You can use graphql api to fetch list of projects like this

$query = <<<'QUERY'
query{
    organization(login: "NOVA-Intergalactic") {
        projects(first: 10) {
            totalCount
            nodes {
                number
            }
        }
        projectsV2(first: 20) {
            nodes {
                id
                title
            }
        }
    }
}
QUERY;
$api = $github->api('graphql')->execute($query);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants