Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,301,203
Community Members
 
Community Events
165
Community Groups

Transition issue via API returning a 400

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

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

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);  

 

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

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!

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
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you