user.emailAddress is a connect.atlassian.com address

Hi,
I’m using the rest API “Send notification for issue” in order to send out an email to a user of my forge app and the syntax requires that I enter an account ID instead of an email address.

var bodyData = { "htmlBody": "The latest test results for this ticket are now available.", "subject": "Latest test results", "textBody": "The latest test results for this ticket are now available.", "to":{ "users": [ { "accountId": "${currentUserId}", "active": false } ]} };

The account Id taken for the “user” API returns a strange email address in the domain “connect.atlassian.com”, and submitting the accountId from the platformContext goes unrecognized.

  1. How do I access the email account of “connect.atlassian.com”?
  2. How can I define the recipient of the notification as an email address instead of a user?
  3. How can I define the user with the platformContext instead of the user API?

Thank you,
Talia

Hi @TaliaSchein ,

It appears the accountId you are passing in (i.e. the value of currentUserId) is that of the user account associated with the app rather than a real user.

  1. How do I access the email account of “connect.atlassian.com”?
    These are not real user email addresses.

  2. How can I define the recipient of the notification as an email address instead of a user?
    To minimise privacy concerns, the API minimises the use of apps dealing with personal data such as email addresses which is why the API does not accept email addresses to identify where to send the email. If you want to send the email to specific users, you must identify them by their accountIds.

  3. How can I define the user with the platformContext instead of the user API?
    If there is no end user in the context in which you wish to invoke the send notification for issue API, then you will have to pass the accountId into the context or store it for retrieval from the non-UI context. For example, if using the async events API, you could pass the accountId when queuing the event. Alternatively, when using a webtrigger, you will probably need to have previously stored information relating to the pending notifications you wish to send, including the accountIds you wish to send the notifications to.

Regards,
Dugald

2 Likes

Thank you @dmorrow!
Thank you for clarifying that I will only be able to send a notification by using an accountID. However, I don’t seem to be able to send a notification even when I draw the accountID from useProductContext, where I see a proper email address is assigned to the user, it still attempts to send the notification to an atlassian connect email address, that I do not see how it is related to the user.
If you are able to further explain how to send a notification to an actual email address, it would be greatly appreciated.
BRGDS,
Talia

Hi @TaliaSchein ,

I created a Forge app to test I was able to use the API to send a message to the current user:

manifest.yml

modules:
  jira:issueAction:
    - key: forge-send-notification-for-issue-hello-world
      function: main
      title: forge-send-notification-for-issue
  function:
    - key: main
      handler: index.run
permissions:
  scopes:
    - 'write:jira-work'
app:
  id: ari:cloud:ecosystem::app/xxxxx

index.jsx

import { fetch } from '@forge/api';
import ForgeUI, {
  render,
  Text,
  IssueAction,
  ModalDialog,
  route,
  useState,
  useProductContext,
  Button
} from '@forge/ui';

const App = () => {
  const context = useProductContext();

  const [isOpen, setOpen] = useState(true);

  if (!isOpen) {
    return null;
  }

  const sendNotificationToMe = async () => {
    console.log(`In sendNotificationToMe`);
    console.log(`context = ${JSON.stringify(context, null, 2)}`);
    const issueKey = context.platformContext.issueKey;
    const body = {
      htmlBody: "The <strong>latest</strong> test results for this ticket are now available.",
      subject: "Latest test results",
      textBody: "The latest test results for this ticket are now available.",
      to: {
        assignee: false,
        reporter: false,
        voters: false,
        watchers: false,
        users: [{
          accountId: context.accountId,
          active: false
        }]
      }
    }
    const bodyData = JSON.stringify(body);
    console.log(`bodyData = ${JSON.stringify(body, null, 2)}`);
    const response = await api.asApp().requestJira(`/rest/api/3/issue/${issueKey}/notify`, {
      method: 'POST',
      headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json'
      },
      body: bodyData
    });
    console.log(`response.status = ${response.status}`);
    if (response.status !== 204) {
      const responseJson = await response.json();
      console.log(`responseJson = ${JSON.stringify(responseJson, null, 2)}`);
    }
  }

  return (
    <ModalDialog header="Hello" onClose={() => setOpen(false)}>
      <Text>Hello world!</Text>
      <Button
        text="Send notification to me"
        onClick={sendNotificationToMe}
      />
    </ModalDialog>
  );
};

export const run = render(
  <IssueAction>
    <App/>
  </IssueAction>
);

To use the app:

  1. Deploy and install it.
  2. Visit an issue.
  3. Select forge-send-notification-for-issue from the issue actions menu.
  4. Click the Send notification to me button.
  5. Wait the email.

Regards,
Dugald