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;
}
}
baseUrivariable set to? Look at theurivariable and ensure it's correct. Also, you shouldawaitthe call toPostAsyncto avoid deadlocks.urivariable. Don't assume it's correct. Compare that URI to the REST API documentation.dev.azure.com? That wouldn't work. You're not providing the complete picture which is going to make it very difficult to help you. Please update your question with the exact URI you're using. Feel free to redact a bit of it for privacy. Also include what version of TFS/Azure DevOps Server you're using.