Github API documentation give instructions to filter repositories by topics. Is there a way to use the API to get the topics from a specific repo?
5 Answers
You can do this with the Github GraphQL API
Query:
{
repository(owner: "twbs", name: "bootstrap") {
repositoryTopics(first: 10) {
edges {
node {
topic {
name
}
}
}
}
}
}
This will return the first 10 topics and the name for each as shown below.
Response:
{
"data": {
"repository": {
"repositoryTopics": {
"edges": [
{
"node": {
"topic": {
"name": "css"
}
}
},
{
"node": {
"topic": {
"name": "bootstrap"
}
}
},
{
"node": {
"topic": {
"name": "javascript"
}
}
},
{
"node": {
"topic": {
"name": "html"
}
}
}
]
}
}
}
}
Test it out in the GitHub GraphQL Explorer

- 13,359
- 7
- 71
- 99

- 5,030
- 2
- 29
- 37
You can do this easily with Github API (it's currently in "preview mode"):
curl -H "Accept: application/vnd.github.mercy-preview+json" https://api.github.com/repos/twbs/bootstrap/topics
{
"names": [
"css",
"bootstrap",
"javascript",
"html",
"jekyll-site",
"scss",
"css-framework",
"sass"
]
}
You need to include extra header Accept: application/vnd.github.mercy-preview+json
.
There is one "but", since it's in "preview mode" it's not supported for production use (please read "Note" and "Warning" sections in link below).
See also:

- 1,343
- 2
- 16
- 36

- 465
- 5
- 16
-
Note that this is not in preview anymore: https://github.blog/changelog/2021-10-14-rest-api-preview-promotions/ – rethab Oct 20 '21 at 08:00
I don't know that there is a way to just get the topics for a repository, but if you do a get for a repository, the repository json object that is returned will have a topics property that is an array of that repositories topics.
At the top of that page of documentation, you will notice that in order to have the topics returned you will need to add a specific header in your GET
request: "Accept":"application/vnd.github.mercy-preview+json"
Hope this helps!

- 1,343
- 2
- 16
- 36

- 11,042
- 5
- 48
- 76
I faced similar problem, so I made a node module that only require one line of code to do that which is
var github_topics = require('github-topics');
var topics = github_topics.gettopics('url_of_repo');
for example
var topics = github_topics.gettopics('https://github.com/Aniket965/blog');
It will return array of topics of that github repository , link to that node module is NPM

- 13,257
- 13
- 53
- 62

- 21
- 3
I added the fetch with Accept Headers:
fetch("https://api.github.com/users/lucksp/repos",
{
method: "GET",
headers: {
Accept: "application/vnd.github.mercy-preview+json"
}
})

- 2,704
- 6
- 31
- 57