Automation - How to change issue Rank to the highest
Asked by Abir Brahem:

Hello,

I am using the automation module to change the Rank of some type of issues:

Looks like I need to use the "**Send web request**"

Can you help me plz,

Thanks,

Abir


Answers:
author: Bill Sheboy
body: Hi [@Abir Brahem](/t5/user/viewprofilepage/user-id/5436278)

What problem are you trying to solve by doing this? That is, *why do this*? Knowing that may help the community suggest additional ideas.

Until we know that...

It is possible to call a REST API function to set the rank of one (or more) issues *relative to another issue*. And so the rule would need the key for the issue above / below which to re-rank the target issue.

This how-to article describes how to call a REST API function from a rule using the Send Web Request action: <https://community.atlassian.com/t5/Jira-Software-articles/Automation-for-Jira-Send-web-request-using-Jira-REST-API/ba-p/1443828>

I recommend contacting your Jira Site Admin before writing this rule as they may provide some additional support.

Kind regards,  
Bill

comments: author: Abir Brahem
body: Hello Bill,

Thank you for the link, now I am able to request the JIRA Cloud API.

I would like to**change the rank** of some type issues to the top.

I found this end point in the documentation:

[The Jira Software Cloud REST API (atlassian.com)](https://developer.atlassian.com/cloud/jira/software/rest/api-group-issue/#api-rest-agile-1-0-issue-rank-put)

I tested with PostMan and I it is possible to change the rank:

**rest/agile/1.0/issue/rank**

++request body:++  
{  
"issues": \[  
"GEN-XXX1" =\> id of the issue to rank, in my case I could use the smart value **{{issue.key}}**  
\],  
"rankBeforeIssue": "GEN-XXX2" =\> the id of highest issue, don't know to get it ???  
}  
Any help plz?  
Thanks,


author: Bill Sheboy
body: **Have you discussed this scenario with your Jira admin yet?** I recommend doing that before you proceed further, as you have not explained the problem you are trying to solve and the conversation with your admin may help.

For example, you do not describe *why* or *when* this change of rank is needed, and those impact the rule trigger and issue context for making changes.

Regarding the rule specifics, as you have already successfully called the REST API function with PostMan and you have the how-to article for calling the function from a rule, you can use that request body as a template in your Send Web Request action.


author: Abir Brahem
body: Hello,

I am a JIRA admin, unfortunately there no expert more then me in the company.

The trigger is**when issu** e created and if **issueType is Bug** (I can't add screenshot, I don't now why..)

I can't use the send Web Request because I need the highest issue key as I descibe in my last message.

Is that clear?


author: Bill Sheboy
body: Let's assume this is for one project and you only care about issues in the backlog. To find the issue which is currently the highest-ranked one, JQL may be used:

project = *yourProjectName* AND status = Backlog ORDER BY Rank ASC

The first one in the list is the highest-ranked issue.

Thus a rule could use the Lookup Issues action with that JQL to gather the first 100 issues found, and the first in the list would be the key needed for the request:

{{lookupIssues.first.key}}


author: Brendan Betheldo
body: Hi [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313) and [@Abir Brahem](/t5/user/viewprofilepage/user-id/5436278) I'm trying to achieve something similar. Reason being is that when issues are created by any one of the 20 members in the team they can be lost in the backlog.

So I want a rule that that runs once a week to find any issues marked as Security and or Compliance (custom field) and move them to the top of the backlog so that when we do sprint planning those items are always first.

Does that help with the *++Why?++*


author: Abir Brahem
body: [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313)

Hi Bill, Thank so much, I succesfully update the Rank finally !

[@Brendan Betheldo](/t5/user/viewprofilepage/user-id/5486079) you request is a little bit more complicated: you can Inspired by my rule (see below). First of all, to change the trigger to **Scheduled**and you need to change the web request body to:

```
{
"issues": {{lookupIssues.key.asJsonStringArray}} ,??
? ? ?"rankBeforeIssue": "{{lookupIssues.first.key}}"
}
```

You need juste to check if the the smart value returns an array of the liste of all the issues to Rank, I am not sure about the right syntax, [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313) what do you think?

This is my rule:

![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/321044i6E8ACB0918EFA98B/image-size/large?v=v2&px=999 "image.png")

Have a nice day,

Abir


author: Bill Sheboy
body: For the field rankBeforeIssue, only one issue key is expected. And so using the first one from the lookup helps ensure that.

Also...the criteria for your linked issues condition and the lookup issues are different. Thus it is possible the lookup issues could return zero or more issues. (It could return zero due to the possibility of timing issues for the Transition Issue step immediately before the lookup, and so not even the trigger issue is found.)

I recommend two changes:

1) Add criteria to the lookup issues action to *exclude the trigger issu*e with:

AND key != {{triggerIssue.key}}

2) Adding a smart value condition after the lookup to ensure at least 1 issue is found:

* first value: {{lookupIssues.size\|0}}
* condition: greater than
* second value: 0

These changes will prevent any attempt so re-rank an issue ahead of itself.


author: Brendan Betheldo
body: Thank you [@Abir Brahem](/t5/user/viewprofilepage/user-id/5436278) and [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313)

Is the authorization in my header just email and API key?

Eg firstname.lastname@email.com.au:xxxxxxxxxxxxAPI_KEYxxxxxxxxxxxxxxx

I've added that in authorization header but I get a 401 and have used the same API key before without issue.


author: Abir Brahem
body: Hello [@Brendan Betheldo](/t5/user/viewprofilepage/user-id/5486079)

The autonfication Value filed is:

```
Basic HzxuhHbhzhdjasYTgdjGfrGHzxuhHbhzhdjasYTgdjGfrG?
```

The key after **Basic** is ***YOUEMAIL:API_TOKEN*** coded id ++base 64++

You can use this online tool to encoded them in base 64

<https://www.base64encode.org/>

Best Regards,


author: Brendan Betheldo
body: Thanks [@Abir Brahem](/t5/user/viewprofilepage/user-id/5436278) and [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313) I got the automation working!


Tags: cloud

jira

jira-cloud