The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

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

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

0 votes
Fabio Racobaldo _Catworkx_
Community Champion
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 _Catworkx_ 

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 _Catworkx_
Community Champion
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 _Catworkx_
Community Champion
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