Unable to use JiraRestClient or rest api to transition issues through workflow

I am trying to transition issues through the workflow using either the JiraRestClient or rest directly.

I have successfully used a combination of both to facilitate creating issues and sub-tasks and searching for issues and sub-tasks.

When attempting to transition an issue I am getting back

Request failed-Http Status: POST https://<our-host>.com/rest/api/latest/issue/QA-10109/transitions returned a response status of 400 Bad Request

Using curl

curl -v -X POST -H "Content-Type:application/json" https://<our-host>.com/rest/api/latest/issue/QA-10109/transitions --user "me:pw" --data-ascii @data.txt

Response:

{"errorMessages":["Can not deserialize instance of java.util.ArrayList out of START_OBJECT token\n at [Source: org.apache.catalina.connector.CoyoteInputStream@716ca6c8; line: 1, column: 15]"]}

data.txt contents

{"update": {

"transition": {"name": "RerunPass"},

"comment": [{"add": {"body": "BuildID: 20121022-14000-2222222\nSystem: \nVersion: 2012 Q3\nTell me more"}}],

"fields": {"resolution": {"name": "RerunPass"}}

}}

any assistance in debugging this or examples of using either the direct rest access or JiraRestClient would be appreciated.

2 answers

1 accepted

Accepted Answer
1 vote
Penny Wyatt Atlassian Team Oct 24, 2012

Hi Gail! You're nearly there, there's just two minor issues with the contents of data.txt:

1) "transition", "comment" and "fields" are underneath "update", but only "comment" should be. "transition" and "fields" should be on the same level as "update".

2) transitions need to be to be referenced by ID, not name (names aren't necessarily unique). You can get the transition IDs by sending a GET request to the same URL.

Here's the modified version of your data.txt that works against my test instance:

{
	"update": {
		"comment": [
			{
				"add": {
					"body": "BuildID: 20121022-14000-2222222\nSystem: \nVersion: 2012 Q3\nTell me more"
				}
			}
		]
	},
	"fields": {
		"resolution": {
			"name": "RerunPass"
		}
	},
	"transition": {
		"id": "5"
	}
}

Thank you. I'll fix that today. I am very happy with the new rest api. It is a vast improvement over the SOAP and old rest.

0 votes

If you want to achive the same with JIRA REST Java Client, you may try that code (for JIRA5+):

// get issue
final Issue issue = client.getIssueClient().getIssue("QA-10109", pm);

// find transition (we need ID)
final Iterable&lt;Transition&gt; transitions = client.getIssueClient()
		.getTransitions(issue.getTransitionsUri(), pm);
		
final Transition transition = Iterables.find(transitions, new Predicate&lt;Transition&gt;() {
	@Override
	public boolean apply(Transition input) {
		return "RerunPass".equals(input.getName());
	}
});

// prepare fields
final List&lt;FieldInput&gt; fields = Arrays.asList(new FieldInput("resolution",
		ComplexIssueInputFieldValue.with("name", "RerunPass")));

// create comment
final Comment comment = Comment.valueOf(
		"BuildID: 20121022-14000-2222222\nSystem: \nVersion: 2012 Q3\nTell me more");

// do actual transition
client.getIssueClient().transition(issue,
		new TransitionInput(transition.getId(), fields, comment), pm);

Does this worked for you?

I will try this too. I like know more than one way to get it done.

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Sep 18, 2018 in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

27,341 views 2 7
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you