Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GitHub API: Get Pinned Repositories

I was looking in the documentation but I couldn’t find how to do this. As the title says: How to get a user’s pinned repositories using the GitHub API ?

like image 765
GabrielBB Avatar asked Oct 20 '25 16:10

GabrielBB


1 Answers

The pinned repositories data is not available on GitHub v3 API. But you can use GitHub's v4 GraphQL API to get the same with the GraphQL query below:

{
  user(login: "GabrielBB") {
    pinnedItems(first: 6, types: REPOSITORY) {
      nodes {
        ... on Repository {
          name
        }
      }
    }
  }
}

The curl request for the above query:

curl -L -X POST 'https://api.github.com/graphql' \
-H 'Authorization: bearer <token>' \
--data-raw '{"query":"{\n  user(login: \"GabrielBB\") {\n pinnedItems(first: 6, types: REPOSITORY) {\n nodes {\n ... on Repository {\n name\n }\n }\n }\n }\n}"
'

The response for the above request:

{
    "data": {
        "user": {
            "pinnedItems": {
                "nodes": [
                    {
                        "name": "xtate"
                    },
                    {
                        "name": "vscode-lombok"
                    },
                    {
                        "name": "react-use-session"
                    },
                    {
                        "name": "Android-CutOut"
                    },
                    {
                        "name": "xvfb-action"
                    },
                    {
                        "name": "Vehicles-API"
                    }
                ]
            }
        }
    }
}

Note: You need to generate a token to access the GraphQL API, which you can generate by following the steps given here

like image 122
Madhu Bhat Avatar answered Oct 23 '25 06:10

Madhu Bhat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!