Filter ActionsAndOperations result or similar finction in REST API 2

Viktor Kuzmychov June 30, 2017

Hi everyone,

Got a question regarding REST API. I have following request:

"<a class='issue-actions-trigger aui-button aui-button-compact aui-button-subtle trigger-happy'id='actions_${issue.id}' title='Actions'" +
"href='/jira/rest/api/1.0/issues/${issue.id.toString()}/ActionsAndOperations?atl_token=${atl_token}'>\n" +
...

It returns list of workflow actions and operations on issue.

I need to reduce output to only get Actions, without Operations (e.g. no Edit, Assign, etc, only workflow transitions)

I can't find any REST 1.0 API description or examples in the net and I can't find anything similar in REST 2. This:

"<a class='issue-actions-trigger aui-button aui-button-compact aui-button-subtle trigger-happy'id='actions_${issue.id}' title='Actions'" +
"href='/jira/rest/api/2/issue/${issue.key.toString()}/transitions?expand=transitions.fields'>\n"
...

doesn't render to what is needed, even though I see result in browser. BTW, results look quite different for these two functions, first one is a clear XML, the other one looks like a simple string.

Is there a way to filter resulting XML to reduce output or similar function in JIRA REST API 2?

 

2 answers

1 vote
Denis Yaparov September 19, 2017

Hi Viktor and others,

Don't know if this still actual, so I'll just describe it for future reference.

I just solved similar task, but in my case I was needed only "Edit" action.

I created custom REST endpoint via Script Runner plugin, which returns narrowed response (only "View" and "Edit", view operation can't be eliminated).

In my scripted field's code I changed "/rest/api/1.0/issues/<subTaskId>/ActionsAndOperations" to "/rest/scriptrunner/latest/custom/getOnlyEditAction?issue=' + subTask.getId()". That trick works pretty fine, it shows small popup with 2 available operations near "dots" button.

In my case it was simple - manually dump real response from Jira in Dev Tools, manually cut it, leave only "Edit" (with empty actions array) and insert it as a response of custom REST with proper issue ID & Key substituted. In topic case it is needed to work with workflow descriptor a little.

PS: REST endpoint returns XML or JSON based on request's HTTP header "Accept". Browser by default requests for HTML and XML, but not JSON, so direct link in browser will return XML.

Oscar Yeung February 13, 2018

Could you provide the code of your custom REST endpoint?

0 votes
Daniel Yelamos [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 4, 2017

Hello Viktor.

I am a bit confused as to what exactly you want to do, and how that relates to scriptrunner.

From what I understand you are simply trying to parse out a response from that REST endpoint. If that is the case you can treat it as text with a regular expression and take what you want out. But then again, I am not sure what it is you want to do with the actual response.

If you would provide a use case for this, I might be able to help you further.

Cheers.

DYelamos 

Viktor Kuzmychov July 4, 2017

Hi Daniel,

Thanks for rsponse! 

To be more specific: I have a scripted custom field which generates output based on found subtask issue in parent issue. So from parent issue I may control the subtask, e.g. the workflow transitions. Along with actuall transitions (actions, marked red) I get the list of available operations (e.g., edit, assign, below marked):

 Screenshot_2.png

So the question is how can I get rid of operations without changing permissions scheme? 

Daniel Yelamos [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 5, 2017

Oh wow this is interesting. Could you send me the response of your rest endpoint? Raw. Formatted with the code blocks? I want to do some testing before I commit to an answer.

Also the more code I get, the easier I can test it on my own machine, so if you want to send me the scripted field code that would be useful.

Cheers!

Viktor Kuzmychov July 5, 2017

 

Here is the response:

<availableActionsAndOperationsWrapper>
<id>290096</id>
<key>PYR-53814</key>
<viewIssue>View Issue</viewIssue>
<atlToken>
TOKEN
</atlToken>
<actions>
<action>241</action>
<name>Set Estimates</name>
</actions>
<actions>
<action>211</action>
<name>Continue</name>
</actions>
<actions>
<action>221</action>
<name>Set Leads</name>
</actions>
<actions>
<action>301</action>
<name>Test</name>
</actions>
<operations>
<name>Edit</name>
<url>/jira/secure/EditIssue!default.jspa?id=290096</url>
<desc>Edit this issue</desc>
<styleClass>issueaction-edit-issue</styleClass>
</operations>
<operations>
<name>Assign</name>
<url>/jira/secure/AssignIssue!default.jspa?id=290096</url>
<desc>Assign this issue to someone</desc>
<styleClass>issueaction-assign-issue</styleClass>
</operations>
<operations>
<name>Assign to me</name>
<url>
/jira/secure/AssignIssue.jspa?atl_token=TOKEN
</url>
<desc>Assign this issue to me</desc>
<styleClass>issueaction-assign-to-me hide-from-opsbar</styleClass>
</operations>
<operations>
<name>Comment</name>
<url>/jira/secure/AddComment!default.jspa?id=290096</url>
<desc>Comment on this issue</desc>
<styleClass>issueaction-comment-issue add-issue-comment</styleClass>
</operations>
<operations>
<name>Attach Files</name>
<url>/jira/secure/AttachFile!default.jspa?id=290096</url>
<desc>Attach one or more files to this issue</desc>
<styleClass>issueaction-attach-file</styleClass>
</operations>
<operations>
<name>Attach Screenshot</name>
<url>
/jira/secure/ShowAttachScreenshotFormAction!default.jspa?id=290096
</url>
<styleClass>issueaction-attach-screenshot-html5</styleClass>
</operations>
<operations>
<name>Watch Issue</name>
<url>
/jira/secure/VoteOrWatchIssue.jspa?atl_token=TOKEN
</url>
<desc>Start watching this issue</desc>
<styleClass>issueaction-watch-issue</styleClass>
</operations>
<operations>
<name>Watchers</name>
<url>/jira/secure/ManageWatchers!default.jspa?id=290096</url>
<desc>Manage the watchers of this issue</desc>
<styleClass>issueaction-manage-watchers</styleClass>
</operations>
<operations>
<name>Convert to Issue</name>
<url>/jira/secure/ConvertSubTask.jspa?id=290096</url>
<desc>Convert this sub-task to issue</desc>
<styleClass>issueaction-subtask-to-issue</styleClass>
</operations>
<operations>
<name>Move</name>
<url>
/jira/secure/MoveSubTaskChooseOperation!default.jspa?id=290096
</url>
<desc>Move this issue to another project or issue type.</desc>
<styleClass>issueaction-move-subtask</styleClass>
</operations>
<operations>
<name>Link</name>
<url>/jira/secure/LinkJiraIssue!default.jspa?id=290096</url>
<desc>Link this issue to another issue or item</desc>
<styleClass>issueaction-link-issue</styleClass>
</operations>
<operations>
<name>Clone</name>
<url>
/jira/secure/CloneIssueDetails!default.jspa?id=290096
</url>
<desc>Clone this issue</desc>
<styleClass>issueaction-clone-issue</styleClass>
</operations>
<operations>
<name>Labels</name>
<url>/jira/secure/EditLabels!default.jspa?id=290096</url>
<desc>Edit this issue's labels</desc>
<styleClass>issueaction-edit-labels</styleClass>
</operations>
<operations>
<name>Delete</name>
<url>/jira/secure/DeleteIssue!default.jspa?id=290096</url>
<desc>Delete this issue</desc>
<styleClass>issueaction-delete-issue</styleClass>
</operations>
<operations>
<name>Add field</name>
<url>/jira/secure/admin/ViewCustomFields.jspa</url>
<desc>Add a field and to the current issue's screens.</desc>
<styleClass>issueaction-fields-add</styleClass>
</operations>
<operations>
<name>Permission Helper</name>
<url>/jira/notimportant</url>
<desc>
Discover why a user does or does not have certain permissions
</desc>
<styleClass>permissionhelper-trigger</styleClass>
</operations>
<operations>
<name>Notification Helper</name>
<url>/jira/notimportant</url>
<desc>
Find out why users receive, or do not receive notifications for this issue
</desc>
<styleClass>notificationhelper-trigger</styleClass>
</operations>
</availableActionsAndOperationsWrapper>

I don't mind to provide the code to you, Can I send it to you directly? 

 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events