Job artifacts api not working


I am trying to download job artifacts with the api provided in this documentation- Job Artifacts API | GitLab
I tried locally with PERSONAL_ACCESS_TOKEN as well in gitlab pipeline with CI_JOB_TOKEN , for both I am getting same error which says authorization required and gives landing page for login.
Any help would be appreciated.