1

I'm currently using the python JIRA to create issues. I want to be able to send an email to specific email addresses after the issue is created. Here is the solution I tried but it doesn't to work.

jira = JIRA(options,basic_auth=('username@email.com','password'))
jira.email_user('test@email.com', 'test email body', title='JIRA Notification')

But the request to email_user gives me a 404 error. "Oops, you've found a dead link". Anyone know an alternate way to send a custom email to a specified email address when a jira issue is created? I would prefer to do this through JIRA Rest API.

dredbound
  • 1,579
  • 3
  • 17
  • 27
  • Why not just rely on the project's Notification Scheme to send issue-related emails? – yossiz74 Mar 19 '17 at 11:17
  • To be more clear - there is no api in JIRA to send an email to a user. Unless you want to use python email capabilities, you need to use the notification schemes, as indicated by @yossiz74 – ZeddZull Mar 19 '17 at 12:27
  • A little more checking indicates that there is a REST API for the notification function, but I don't think that jira-python exposes it. It isn't hard to add another api to jira-python, but the schema for this API is fairly complex. – ZeddZull Mar 19 '17 at 12:33
  • @ZeddZull Do you have a link to the notification function in the REST API? – dredbound Mar 19 '17 at 17:43
  • Never mind I found it. https://docs.atlassian.com/jira/REST/cloud/#api/2/issue-notify – dredbound Mar 20 '17 at 19:36

1 Answers1

2

In case anyone else has this issue, here is how you can send a custom email using the JIRA rest api (in python):

import requests

url = "https://jiraserver.atlassian.net/rest/api/2/issue/{issue number or key}/notify"

notify_data = {
        "subject": "Duis eu justo eget augue iaculis fermentum.",
        "textBody": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque eget venenatis elit. Duis eu justo eget augue iaculis fermentum. Sed semper quam laoreet nisi egestas at posuere augue semper.",
        "htmlBody": "Lorem ipsum <strong>dolor</strong> sit amet, consectetur adipiscing elit. Pellentesque eget venenatis elit. Duis eu justo eget augue iaculis fermentum. Sed semper quam laoreet nisi egestas at posuere augue semper.",
        "to": {
            "users": [
                {
                    "name": "JIRA user"}] #Make sure you set permission for receiving notifications from self in your profile if you use same user you are logged in as"
        },

    }

requests.post(url,auth=('jira username','jira password'), json=notify_data)
dredbound
  • 1,579
  • 3
  • 17
  • 27