Jerry_Knight
Jerry_Knight

Reputation: 41

Can't connect to my repository in GitLab using c#

I created a subgroup in GitLab where I have a test project. I created an access token for that project. I'm receiving error 401 or error 404.

I'm going through the GitLab api and not sure if I'm formatting this incorrectly to access my project. But I'm basing it off the examples they show. Any direction or feedback would be most appreciated.

Below is the code:

    private static async Task ProcessRepositories()
    {
        client.DefaultRequestHeaders.Accept.Clear();          
        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
        client.DefaultRequestHeaders.Add("User-Agent", ".NET Foundation Repository Reporter");

        var streamTask = client.GetStreamAsync("https://gitlab.com/api/v4/projects/someGroup/someSubgroup/myNewDirectory/tempfiles/repository/commits?private_token=myToken");

        var repositories = await JsonSerializer.DeserializeAsync<List<Repository>>(await streamTask);

        foreach (var repo in repositories)
        {
            Console.WriteLine(repo.name);
        }
    }

Upvotes: 0

Views: 468

Answers (1)

Jerry_Knight
Jerry_Knight

Reputation: 41

One answer to this question, I had the formatting of the url incorrect.
Should've been:

{host}/api/v4/projects/projects/{my project id}

That will at least give me the basic info I needed. From there I need to see how to get just the files. But hopefully that little nugget of info helps someone else.

Upvotes: 1

Related Questions