Example for how to get Package Metadata from Azure DevOps Rest-Api Artifacts using c#

Riedel, Lukas / ESSA 1 Reputation point
2022-02-10T09:43:29.993+00:00

Hello everybody!

I am trying to read the Package Version of a Universal Package sitting in an Artifacts organization scoped Feed using the Azure DevOps Rest-Api in c#.

I have tried 2 approaches:

  1. I wanted to read any Packageinformation from our feed, so i tried to get all Packages and since there is a documentation for the Api I used this "https://learn.microsoft.com/en-us/rest/api/azure/devops/artifacts/artifact-details/get-packages?view=azure-devops-rest-6.0" string credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", "PAT-Token")));
    //use the httpclient
    using (var client = new HttpClient())
    {
    client.BaseAddress = new Uri($"https://dev.azure.com/organization/project/"); //url of your organization
    client.DefaultRequestHeaders.Accept.Clear();
    client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", credentials);
                 //connect to the REST endpoint              
                 HttpResponseMessage response = client.GetAsync("_apis/packaging/Feeds/Development/packages?api-version=5.1-preview.1").Result;  
                 //_apis/projects?api-version=5.1  
                 //_apis/packaging/feeds/{feedId}?api-version=6.0-preview.1  
    
                 if (response.IsSuccessStatusCode)  
                 {  
                     string value = response.Content.ReadAsStringAsync().Result;  
                     value.ToString();  
                 }  
             }  
    

The "response" variable had a 404 in the end

  1. The second one was with VisualStudio.Services Namespace string organizationName = "organization";
    VssCredentials credentials = new VssCredentials();
            Uri organizationUrl = await VssConnectionHelper.GetOrganizationUrlAsync(organizationName);  
    
            VssConnection connection = new VssConnection(organizationUrl, credentials);  
    
            HttpClient based = connection.GetClient<VssHttpClientBase>;  
    

But from here i found no way to get Package information.

Im pretty lost because nobody seems to have the same Problem as me, am I doing something wrong?

Thanks in advance!!!!

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,288 questions
{count} votes