Send email to a project role
Platform Notice: Cloud - This article applies to Atlassian products on the cloud platform.
Summary
Sometimes we need to send emails to specific project role users, however, the send email action in the automation can send emails to user picker fields and groups only. In this article, we show how to create an automation to get the users’ email addresses within a role, and with that, be able to send emails to them.
This feature request is opened to have this implemented:
Requirements
Identify the role you would like to send the email to:
Access the following URL to get the list of the roles you have within the project, as we will use the role id in order to achieve it:
https://<yourinstance>.atlassian.net/rest/api/3/project/{projectid}/role/
You should see the list of roles available for your project, you should be able to identify the role id in the URLs listed, right after …/role/{roleid}.
When sending web requests in Jira, we use the Authentication header in base64. Please follow the steps on this document, in case you need to generate it:
Solution
Trigger: Issue Created (You can select the trigger based on your case scenario)
Action: Send a web request to the following endpoint:
https://<yourinstance>.atlassian.net/rest/api/3/project/{projectid}/role/{roleid}
With that, we should receive a payload with everyone in the Service Desk Team role
Branch Using an advanced branch, we should be able to execute the following actions for each of the results and add it to a variable, in this example {{newusers}}
Action: Send a new web request to get the list of users' email addresses:
https://<yourinstance>.atlassian.net/rest/api/3/user/search?accountId={{newusers}}
Action: Send email to {{webResponse.body.emailAddress}}, which contains all the users' email addresses
Your role should look like this:
With that, we should be able to send individual emails to all of the members of the specified role.
IMPORTANT NOTE: Keep in mind that for this workaround to work as I mentioned, the users who should receive the email (Service Desk Team), must have their email address visible, under their account settings, as per the following document:
Update your profile and visibility settings
Log in to your Atlassian account and view the Profile and visibility page: https://id.atlassian.com/manage-profile/profile-and-visibility
Click a profile field to add or edit the profile information. Your changes will take effect within five minutes everywhere your profile appears.