GitLab Runners API::401 Unauthorized

Hi there.

Try to use GitLab Runners API with simple request:

$ curl --header "PRIVATE-TOKEN: <token>" "https://gitlab.com/api/v4/runners/all"

and got the error:

{"message":"401 Unauthorized"}

How I can fix it?

Thanks.

Hi @tcolonel , welcome to the GitLab Community Forum! :tada:

The /api/v4/runners/all endpoint will return a list of all runners in the GitLab.com GitLab instance, regardless of who registered the runner or if the runners are available to you. Access to this endpoint is restricted to users with administrator access. Since you’re not a GitLab.com administrator, the 401 Unauthorized status code is expected.

To get a list of runners available to your user, you can use the api/v4/runners endpoint. Runners API | GitLab

1 Like

Still the same error. What next?

From your link - Runners API | GitLab:

[[runners]]
token = “<authentication_token>”

curl --header “PRIVATE-TOKEN: <your_access_token>” “https://gitlab.example.com/api/v4/runners

<authentication_token> = <your_access_token> or not?

Thanks.

Good question!

The <your_access_token> value refers to your user’s Personal Access Token. You can create a personal access token for your user at https://<your_gitlab_url>/-/profile/personal_access_tokens

2 Likes

In your docs the diff story ) Therefore, it confuses a little …

So now it works but not as I expected … I have a few projects where is I am not Owner but Maintainer. Is it possible to get info about runners from that projects?

Thanks.

The global /api/v4/runners endpoint only returns “Owned Runners”, so it won’t list runners on projects where you have maintainer access.

To get runners on projects where you’re a maintainer, you can use the “List Project Runners” API endpoint

1 Like

Now I see. Thanks.

So at first I need to get all my projects and then get all possible runners from these projects? Is it possible to get all possible runners for several projects? So it’s may be like this:

GET /projects/:id,:id,:id,:id/runners

Thanks.