I am attempting to add a work task using Azure Apis but I keep getting a 404 error. I attempted to do a get all projects and this works (so my authentication token is working fine). I even granted all Azure Permissions to the token and it still returns a 404 error.
public class Main
{
public static void Main(string[] args)
{
AzureClient ac = new AzureClient();
var task = ac.AddTask();
}
}
public class AzureClient
{
private readonly HttpClient _client;
public AzureClient()
{
_client = new HttpClient()
{
Timeout = TimeSpan.FromSeconds(30)
};
_client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
// ADDED PAT HERE TO CLIENT
}
public async Task AddTask()
{
List<object> task = new List<object>
{
new { op = "add", path = "/fields/System.Title", value = "Test"}
};
string jsonTask = JsonConvert.SerializeObject(task);
string baseUri = "some base uri";
string uri = $"{baseUri}/_apis/wit/workitems/$Task?api-version=5.0";
// RESPONSE HERE RETURNS 404
var response = _client.PostAsync(uri, new StringContent(jsonTask, Encoding.UTF8, "application/json-patch+json")).Result;
}
}