'Gitlab API filter projects by topic (project tag)
I'm in trouble filtering projects by "tag" with the api (named topics in project settings).
I would get the same result as the following UI query https://gitlab.xxxxxx.com/explore/projects?tag=ruby
It returns all project that are tagged with the "ruby" topic.
Here is an example of result I have with the api when describing a single project:
curl --header "Authorization: Bearer $GITLAB_TOKEN" "https://gitlab.hostname.com/api/v4/projects/42?simple=true" | json_pp
...
"tag_list" : [
"ruby"
],
...
According to the documentation (https://docs.gitlab.com/ce/api/projects.html#list-all-projects) I should be able to filter on project tag_list using topic parameter
curl --header "Authorization: Bearer $GITLAB_TOKEN" "https://gitlab.hostname.com/api/v4/projects?topic=ruby&simple=true" | json_pp
But this query returns all my projects, even those without any tag or the wrong ones
I tried using "tag" or "tag_list" instead of "topic" but nothing worked as I expected
Is someone have an idea on how to proceed ?
Note that I'm using gitlab CE 13.9
Solution 1:[1]
As you mentioned, you're using gitlab version 13.9 and the ability of filtering projects by tag_list or topic has come with version 14 and later.
See: https://docs.gitlab.com/13.11/ee/api/projects.html#list-all-projects
Solution 2:[2]
Another approach: using the new API topics.
See GitLab 14.5 (November 2021)
Manage project topics with the API
In this release, thanks to Jonas Wälter’s contributions, adding topics in project settings is easier than ever.
In addition to the latest project topic management features in the UI, you can now use the API to retrieve topics by list or ID.
We’ve also made it possible for administrators to create or edit topics through the API. This introduces full parity between project topic management in the UI and API.
See Documentation and Issue.
Listing projects assigned to a topic is still done through the project API, though.
But the API around topics is now more complete.
That API also includes, with GitLab 14.9 (March 2022):
API endpoint to delete project topics
In a previous release, we added the ability to create and manage project topics that are used to categorize projects and find similar new projects. However, we did not create a way to delete them.
In this release, thanks to Timo Furrer’s contribution, we added an API endpoint to delete project topics to make topic management more neat and efficient.
See Documentation and Issue.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Mostafa Fakhraee |
| Solution 2 |
