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 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!
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
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
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
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.
No, you cannot do it like that. You would have to use multiple API commands. First, get the full project list using the appropriate API command from the docs, and extract/filter the ID. Then use the second API command looping over the ID list to then get a list of the runners. So you would have to script that.