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

Gail Stewart October 23, 2012

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

1 vote
Answer accepted
Penny Wyatt (On Leave to July 2021)
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 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"
	}
}

Gail Stewart October 24, 2012

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
Aleksander Mierzwicki
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 29, 2012

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?

Gail Stewart October 31, 2012

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