How to get GitLab project name by using Project id in GitLab API

I have a script which prints project id with other attributes like allowed to push , allowed to merge I need to replace project name with project id. How is this possible?

PROJECT=$(cat /var/opt/gitlab/.project)
TOKEN=$(cat /var/opt/gitlab/.token)
URL=$(cat /etc/gitlab/gitlab.rb | grep external_url | grep -vE ‘pages|registry’ | grep -v ^# | cut -f 2 -d “'”)
projectId=( $(curl -sS --header “PRIVATE-TOKEN: $TOKEN” “$URL/api/v4/projects?&per_page=100&sort=asc&page=[1-50]”| jq -r )
for i in “${projectId[@]}”
branch1=( $( curl -sS --header “PRIVATE-TOKEN: $TOKEN” “$URL/api/v4/projects/$i/protected_branches” | jq -r “.” | jq -r “.name”) )
branch1=( $( curl -sS --header “PRIVATE-TOKEN: $TOKEN” “$URL/api/v4/projects/$i/protected_branches” | jq “.path_with_namespace”) )
for branch in “${branch1[@]}”
Allowed_to_push=( $(curl -sS --header “PRIVATE-TOKEN: $TOKEN” “$URL/api/v4/projects/$i/protected_branches/”$branch"“| jq -r .push_access_levels |grep -o '“access_level_description”: “[^”]”’ | grep -o '“[^”]*"

        Allowed_to_Merge=( $(curl -sS --header "PRIVATE-TOKEN: $TOKEN" "$URL/api/v4/projects/$i/protected_branches/"$branch""| jq -r .merge_access_levels |grep -o '"access_level_description": *"[^"]*"' | grep -o '"[^"]*"
```) )
        Allow_to_force_push=( $(curl -sS --header "PRIVATE-TOKEN: $TOKEN" "$URL/api/v4/projects/$i/protected_branches/"$branch""| jq -r .allow_force_push) )
echo  -e "$branch,\t\t\t\t$i,\t\t\t\t$Allowed_to_push,\t\t\t\t$Allowed_to_Merge,\t\t\t\t$Allow_to_force_push" >> input.json

Hi @codelearner1029 :wave: :slightly_smiling_face:

You can use this project API to get the JSON with the project infos :slightly_smiling_face: In there you can find:

  • name which is the name of the project (e.g. Diaspora Project Site)
  • name_with_namespace which is the full name of the project with its full path (e.g. Diaspora / Diaspora Project Site)
  • path which is the path of the project (e.g. diaspora-project-site)
  • path_with_namespace which is the full path of the project which you can use to compose the URL to get to the project (e.g. diaspora/diaspora-project-site)