Get Atlassian ID from Jira for use in Workflow

Has anyone tried to get the Atlassian accountID (via Jira) of a user and store it as a variable in a workflow?

Atlassian no longer allows us to create tickets via API using the friendly usernames in picker fields – it now requires the accountID. Has anyone created a workflow where they have to retrieve the accountID for an employee, store it as a custom variable, and then generate a jira ticket from there?

Thank you!
Pamela

Hi Pamela,

Could you provide us some more input here, basically a high-level logic which you are planning to implement

Hi Amit,

I want to create leaver tickets in Jira using workflows.
In order to generate the leaver ticket, I need to put the employee name in a user picker field.

However, I can’t populate the user picker field with the employee email address or username, I need to search for the employee’s accountID from jira using the email address and then store it as a variable in the workflow?

The jira documentation for doing the user search:
https://confluence.atlassian.com/jirakb/how-to-get-the-accountid-for-customer-accounts-in-jsm-1283494265.html

(I am not sure if that makes it more or less clear. :smiley: )

So, I am wondering if anyone has done that using workflows.

Hi @pgustavsonsh ,

I have personally not worked on this usecase, but for a similar kind of use case i did the APPROACH 2.

This is what i am assuming [APPROACH 1]:

  1. You have JIRA source configured and it is correlated with the identity.
  2. Account ID on JIRA source is accountID that you want to use to search the user in JIRA

Now if the above scenario is true, then it should be straight forward;

  1. In workflows use getidentity [Action] to get the identity information,
  2. Next, using getAccounts [action] filter such that you get only JIRA Source Account ID,
  3. Once you have that you can perform other operations as required.

This is what i am assuming [APPROACH 2]:

  1. You have JIRA api, to search the user and get the accountID of the user.

Now if the above statement is true, then :

  1. Call the getIdentity [Action] store the email in the variable so it can be used further.
  2. Call the JIRA API and in the api, pass the filter as email address you have received from #1
  3. Once you have the response, parse the response such that you can retrieve the accountID.
    i) to achieve this #4 use https://jsonpath.com/ to retrieve specific object “accountID” from JSON response.
    ii) once you have the ID, pass it further .

Hope this helps.

That’s what I was trying to do, but I am struggling with how to pass the value to the variable?

I have the action HTTP Request – that calls the API using the Request URL – https://[myenvironment]/rest/api/3/user/search?query={{$.getIdentity.attributes.email}}

When I called it via Postman, it returns something like this:

[
    {
        "self": "https://[myenvironment]/rest/api/3/user?accountId=xxxx2039579cfb64f5xxxxxx",
        "accountId": "xxxx2039579cfb64f5xxxxxx",
        "accountType": "atlassian",
        "emailAddress": "[email protected]",
        "avatarUrls": {
            "48x48": "[avatarURL1]",
            "24x24": "[avatarURL2]",
            "16x16": "[avatarURL3]",
            "32x32": "[avatarURL4]"
        },
        "displayName": "First Last Name",
        "active": true,
        "timeZone": "America/Chicago",
        "locale": "en_US"
    }
]

So, after the HTTP Request, I add an operation Define Variable and create a new variable called “accountID” like this? (I am not sure what the body is supposed to look like to grab the variable)

{
  "name": "Jira AccountID ",
  "description": "",
  "transforms": [],
  "variableA.$": "$.hTTPRequest2.body.accountId"
}

Am I going in the right direction?

just one minor change in the filter for variable; can you try with this:

{
  "name": "Jira AccountID ",
  "description": "",
  "transforms": [],
  "variableA.$": "$.hTTPRequest2.body[0].accountId"
}

Looking at the response it looks like an Json array and as you are only tapping into one account at a time so we should be good to say that there will be one response only hence added [0] and then we get the accountId.

Do update me on what’s the outcome and Hope this helps :slight_smile:

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.