Home > Enterprise >  Unable to list regex protected branch using Gitlab API
Unable to list regex protected branch using Gitlab API

Time:02-20

I am trying to get GitLab protected branches of a project using curl API request, getting all the relevant branches of type "xyz", "xyz-*". But I am unable to get the branch that has a "/" in its name.

Using below curl request which is failing for branch "release/R*" :

curl -H "Content-Type: application/json" --header "PRIVATE-TOKEN: <TOKEN>" "https://xyz.gitlab.com/tools/gitlab/api/v4/projects/492/protected_branches/'release/R*'"

It gives an output {"error":"404 Not Found"} Need help to get the output for all the branches, irrespective of the regex, if possible.

CodePudding user response:

To use in a curl request the name of a branch that contains / you need to use its encoded form /

Change

release/R

To

release/R

To test it, try to query for a single branch (https://docs.gitlab.com/ee/api/branches.html#get-single-repository-branch)

For a branch with name E.g. release/Rated

curl --header "PRIVATE-TOKEN: <TOKEN>" "https://example.com/gitlab/api/v4/projects/<project_id>/repository/branches/release/Rated"
  • Related