Using /issue/{issuekey}/notification REST endpoint, how to use email address

Rich Scire July 18, 2021

I'd like to send notifications using the following in the Users section:

  • Hard-coded email address
  • A text field holding an email address
  • A single user picker field
  • A  multiple user user picker
  • A singe or multiple group picker field

I don't see any way to do these things. Is there a way?

1 answer

1 accepted

1 vote
Answer accepted
David Bakkers
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 18, 2021

Hello @Rich Scire 

Are you referring to the /rest/api/3/issue/{issueIdOrKey}/notify endpoint?

If so, can you provide the content of the POST request you're making to that endpoint, and the method / tool you're using to submit that request.

Rich Scire July 20, 2021
It's embedded in a Scriptrunner listener. Here is the code:

def resp = post("/rest/api/2/issue/${issueKey}/notify")
.header("Content-Type", "application/json")
.body([
subject : subject,
textBody: body,
htmlBody: "<p>${htmlBody}</p>",
to : [
users: [[
accountId : b2b_ops
]]
]
])
.asString()

I know I can include the assignee, reporter, groups and users. Can I add an email address or a text field that contains and email address?

Thanks for your help.

David Bakkers
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 20, 2021

Hello @Rich Scire 

When you drill down through the documentation for that REST API endpoint as to what the NotificationRecipients can contain, it says that is can contain a value users which can be an array of UserDetails which is the type:

accountId

string

The account ID of the user, which uniquely identifies the user across all Atlassian products. For example, 5b10ac8d82e05b22cc7d4ef5.

Max length: 128

So, in short, the only things that can be used as the recipient of the to part of the request for users are accountIDs, nothing else.

If you want to notify users other than the assignee, reporter, group etc, you're going to need to do a lookup of those users' accountIDs first, based on their email addresses, by using the find users endpoint , like this:

/rest/api/3/user/search?query=whatever@whatever

 Once you know all their accountIDs, then you can put that information into the ScriptRunner request's body.

 

To me, it sounds like you'd be better of using a group to contain all the users you want to notify, because a group can be a recipient. The next level of complexity up from that is to consider a custom notification scheme, but that is really using a sledge hammer on a brad.

Suggest an answer

Log in or Sign up to answer