Automatically send an email to all members of a Jira project role
Platform Notice: Cloud Only - This article only applies to Atlassian products on the cloud platform.
Summary
Sometimes we need to send emails to specific project role users. The send email action in Jira Automation can send emails to user picker fields and groups only.
In this article, we 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:
Solution
Determine project and role IDs
IMPORTANT NOTE: Users intended to receive the email must have their email address visible under their account settings. Please refer to:
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
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,
We will use the role ID in our automation rule, as project role names aren't supported
https://<yourinstance>.atlassian.net/rest/api/3/project/{projectid}/role/
This endpoint lists roles available for your project
You should be able to identify the role ID in the URLs listed, for example: /role/{roleid}
When sending web requests in Jira, we use the Authentication header encoded as base64
Please follow the steps in this document to generate a new token: Automation for Jira - Send web request using Jira REST API
Automation rule to notify each email address in a project role
Trigger: Work item Created
You can select another trigger based on your requirements
Action: Send a web request
Request URL:
https://<yourinstance>.atlassian.net/rest/api/3/project/{projectid}/role/{roleid}
Replace the Project ID and Role ID with the appropriate values from above
Headers:
Authorization: Basic <base64_encoded_api_token>
Content-type: application/json
HTTP Method: GET
Web Request body: Empty
Delay execution...: checked
This request generates a payload with all email addresses in the specified project role.
Add a Branch - Advanced branch:
Smart value:
{{webResponse.body.actors.actorUser.accountId}}
Variablename: newusers
In our advanced branch, we will execute the subsequent actions for each of the results (each email address) as a variable, in this example {{newusers}}
Add a new Send web request action:
Request URL:
https://<yourinstance>.atlassian.net/rest/api/3/user/search?accountId={{newusers}}
Headers:
Authorization: Basic <base64_encoded_api_token>
Content-type: application/json
HTTP Method: GET
Web Request body: Empty
Delay execution...: checked
Add a Send email action:
To:
{{webResponse.body.emailAddress}}
Subject and Content: Your choice
Was this helpful?