Cannot delete image tag via API

Cannot delete image tag via API

The documentation mentions how to delete an image tag from the container registry (Container Registry API | GitLab).

I tried using the snippet from configuration in CI. This is the particular step:

  - >                                                                                                                                                                                                  
    TOKEN=`curl --request GET --user "${CI_REGISTRY_USER}:${CI_REGISTRY_PASSWORD}" "${CI_SERVER_URL}/jwt/auth?account=${CI_REGISTRY_USER}&service=container_registry&scope=${SCOPE}" | jq -r .token`    
    curl --request DELETE --header "Authorization: Bearer ${TOKEN}" --header "Accept: application/vnd.docker.distribution.manifest.v2+json" "https://${CI_REGISTRY}/v2/${CI_REGISTRY_IMAGE}/tags/reference/latest" 

However, I get 401 error:

{"errors":[{"code":"UNAUTHORIZED","message":"authentication required","detail":[{"Type":"repository","Class":"","Name":"***","Action":"delete"}]}]}

I tried even with the original ${CI_COMMIT_SHORT_SHA} as reference, I tried it manually with my personal credentials. All with the same results. The name from error output matches the value of $CI_REGISTRY_IMAGE as well. I cannot find what the problem is.

Also worth of noting, I am using