0

I am trying to run a simple API request to GitLab through powershell 5.1. After generating an access token with all privileges using the Web UI I tried to run the following:

invoke-restmethod https://gitlab.com/api/v4/projects?private_token=<my_private_token>/<project_id>

Unfortunately, I get an error:

invoke-restmethod : {"message":"401 Unauthorized"} At line:1 char:13 + $response = invoke-restmethod https://gitlab.com/api/v4/projects?priv ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (System.Net.HttpWebReques t:HttpWebRequest) [Invoke-RestMethod], WebException + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.Pow erShell.Commands.InvokeRestMethodCommand 

Why am I getting 401 error when I try to access project related information?

1 Answer 1

1

The parameter should come at the end of the URL:

Invoke-RestMethod -Uri https://gitlab.com/api/v4/projects/1234567?private_token=$my_private_token 

I prefer to pass the token in the header:

Invoke-RestMethod -Headers @{ 'PRIVATE-TOKEN'=$_my_private_token } -Uri http://gitlab.com/api/v4/projects/1234567 

https://docs.gitlab.com/ee/api/#personalproject-access-tokens

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.