Transition issue via API returning a 400

HLH May 4, 2022

I'm trying to transition issues via the API using .NET but I'm consistently getting a 400 error back. I'm wondering if anyone can see anything obvious that I'm doing wrong?

Code:

string example = @"{
""id"": ""221""
}";

string ticketjson = JsonConvert.SerializeObject(example); 

string postUrl = "https://myurl/rest/api/2/issue/" + issueKey + "/transitions";
System.Net.Http.HttpClient client = new System.Net.Http.HttpClient();
client.BaseAddress = new System.Uri(postUrl);
byte[] cred = UTF8Encoding.UTF8.GetBytes("username:pwd");
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(cred));
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));

var content = new StringContent(ticketjson, Encoding.UTF8, "application/json");
var response = client.PostAsync(postUrl, content).Result;
if (response.IsSuccessStatusCode)
{
string result = response.Content.ReadAsStringAsync().Result;

return result;
}
else
{
unauth.Text = "There has been a problem submitting your comment. Please try again.";
return response.StatusCode.ToString();
}

 

The transition exists and when I go to the postUrl I can see it: 

image.png

Any help would be appreciated!

1 answer

0 votes
Fabio Racobaldo _Herzum_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 4, 2022

Hi @HLH ,

as specified here https://docs.atlassian.com/software/jira/docs/api/REST/8.22.2/#issue-doTransition , error 400 means that there's no transition specified.

Please specify just transition id and not other values like name ,to ...

...

}, "transition": { "id": "5" },

...

Take a look to the provided example.

Fabio

HLH May 4, 2022

Hi @Fabio Racobaldo _Herzum_ 

Thanks for your response :) 

I think that's what I'm doing? This is the code that I'm passing to it. Is this id the correct one? I'd assumed from the screenshot that I included that because it as top level it was the correct id to reference, but maybe not! 

string example = @"{
""id"": ""221""
}";

 I then convert it to json and pass it to the post: 

string ticketjson = JsonConvert.SerializeObject(example);  

 

Fabio Racobaldo _Herzum_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 4, 2022

Please could you check, through the log file, request structure sent to JIRA?

HLH May 4, 2022

Hi, is it the atlassian-jira.log file? Sorry haven't used the log files much before! 

I can find other rest api calls in there for /comment, but nothing for /transitions or the specific issue key so I might be in the wrong place!

Fabio Racobaldo _Herzum_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 4, 2022

take a look to the <JIRA HOME Folder>/log/atlassian-jira.log file in order to figure out what is the error and to figure out if the call has correctly managed by JIRA

Like HLH likes this

Suggest an answer

Log in or Sign up to answer