I am trying to transition a jira ticket and update some fields as I go. I can transition the issue and not update any other fields and it only complains about 'no content' in the issue. But when I try to add content get "Status Code 400 - Bad Request" error.
This block of code is what I successfully use to transition the issue with no content
public async void updateTicket()
{
string BaseUrl = "https://jira";
string Username = "user";
string Password = "pas";
string restUrl = String.Format("https://jira/rest/api/2/issue/{0}/transitions?expand=transitions.fields", "ABC-12345");
using (var httpClient = new HttpClient())
{
using (var request = new HttpRequestMessage(new HttpMethod("POST"), restUrl))
{
string base64Credentials = GetEncodedCredentials();
request.Headers.Authorization = new AuthenticationHeaderValue("Basic", base64Credentials);
// successfully updates ticket, but no content
var requestBody = new
{
transition = new
{
id = "11"
}
};
var jsonRequestBody = Newtonsoft.Json.JsonConvert.SerializeObject(requestBody);
request.Content = new StringContent(jsonRequestBody);
request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
var response = await httpClient.SendAsync(request);
if (response.StatusCode == HttpStatusCode.OK)
{
Console.WriteLine("Pass");
}
else
{
Console.WriteLine($"Failed to update transition. Response: {response}");
Console.WriteLine($"Failed to update transition. Status code: {response.StatusCode}");
Console.WriteLine($"Failed to update transition. RequestMessage: {response.RequestMessage}");
}
}
}