I have read the Azure DevOPS REST API documentation and tried to implement it to my Web Application multiple times but to no avail. I have no experience using REST API's and I would appreciate if someone could guide me into the right direction.
I am trying to create a POST Request for Azure DevOps Repositories and wish to create a new repository through the API method. I have read the documentation on this, but I have no idea how to implement this in my own project. I understand how I need to create a connection to the API, but no idea how and where I write the Request Body for this method. I would like to know how I specify the name of the new repository. I'm actually very clueless and have no idea how to use the REST API in general.
I am using Visual Studio with .NET Core 3.0 and plan to use this with React.js
Here's the code I'm working with so far, and I have no idea where to go from here:
public class AzureDevOps {
public static async void GetRepositories()
{
try
{
var personalaccesstoken = "PAT_FROM_WEBSITE";
using (HttpClient client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Add(
new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",
Convert.ToBase64String(
System.Text.ASCIIEncoding.ASCII.GetBytes(
string.Format("{0}:{1}", "", personalaccesstoken))));
using (HttpResponseMessage response = await client.GetAsync(
"https://dev.azure.com/{organization}/_apis/git/repositories?api-version=5.1"))
{
response.EnsureSuccessStatusCode();
string responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseBody);
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
}
I would appreciate any clarification on this matter, as well as some examples on how to use the REST API. Thanks in advance!
await client.GetAsync(...) while what it sounds like you need is an HTTP POST requestawait client.PostAsync(: blog.jayway.com/2012/03/13/…