Smart value to iterate over list of User names received via webRequest

Harsh
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.
February 28, 2024

Hello All,

 I am using webRequest for the first time in Jira Data Center, and facing some challenges.

I am retrieving list of users in JSON format via the Web Request and storing them in the variable Users. Now what I want is to iterate over this list and send a the email to them, is there a smart value to achieve this?

I am using Data center, any leads will be helpful. 

1 answer

0 votes
Kalyan Sattaluri
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.
February 28, 2024

Hello @Harsh 

Do you want to send 1 email with all your users as recipient or 1email per recipient? I dont think the latter is easily possible in DC because you dont have advanced branch option.

BTW, Variable you created is just text. Typically you need to do atleast  a split on "," on it to convert to a list so you can iterate over.

If you want to just send 1 email, you dont need to iterate this variable, just make sure emails are separated by semi colon.

but if you want to send 1 email per user, without complicated logic its not possible.

 

Harsh
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.
February 29, 2024

Hi @Kalyan Sattaluri 

I am looking for the first one -  send 1 email with all your users as recipient. I am aware of the Advanced Branch in Cloud. IS there is a way to achieve this in DC ?

 

Thank you

Kalyan Sattaluri
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.
February 29, 2024

Hi @Harsh 

If its 1 email, its straight forward.. Do you have email addresses in your JSON? You can directly reference the email list.. for ex, If your emails are in {{webResponse.body.emailAddress}} , you just use that in your to field. You dont need to store it in a variable. Have you tried it? Or can you share details on your "users" data and where is the issue?

Harsh
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.
March 1, 2024

Hi @Kalyan Sattaluri 

So I am getting all the users who are Administrator role in JSON format ( 10 users), similar to Send email to a project role | Jira | Atlassian Documentation, although it is in cloud; and then storing it in a variable.

But unfortunately it does not have email address in JSON. I am getting Name - which is ID, and DisplayName.

What I want is some how the rule sends email to all 10 users fetched via Web Request JSON. But like you mentioned JIRA data center does not have advanced branching.

Hope this helps.

 

 

Kalyan Sattaluri
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.
March 1, 2024

Hello @Harsh 

I am guessing what you have is Account IDs of these users?

If I assume so, Given that you have stored them in a variable, you can "format" (replace commas with &) that string and make a call to Bulk Get Users endpoint and get a list back.

 

If that end point is like below:

And you formatted your variable like below:

  • accountId=5b10a2844c20165700ede21g&accountId=5b10ac8d82e05b22cc7d4ef5

Then your final URL will be like below:

 

From above response, you should be able to extract emails addresses and send your bulk email.. 

Now the documentation says it returns paginated response with maxresults at 100 each time, but since you have only 10 users I would think you should be able to retrieve that much with out out of the box..

I havent had a need to try this but let me know issues. Especially the part about what do you currently have, usernames or accountIDs.

 

Please try and let me know.

 

Harsh
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.
March 1, 2024

Hi @Kalyan Sattaluri 

Thank you for the suggestions.
But the identifier for ID is not accountId, it is name. 

Example:

"name": 114548 (which is actually the accountID)

"displayName": harsh

 

I will still try out the above and let you know

Kalyan Sattaluri
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.
March 1, 2024

Hmm, if its like you have, I am not sure if it will work, lets me also look around in our instance. In the mean time do check like below for quick confirmation:

  • Given you have logged into Jira,
  • Open a new tab and just hit enter to know if you are seeing results:

https://mydomain.atlassian.net/rest/api/2/user/bulk?accountId=114548 

Harsh
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.
March 1, 2024

Hi @Kalyan Sattaluri 

getting error 404 with the below message- 
This XML file does not appear to have any style information associated with it. The document tree is shown below.

Kalyan Sattaluri
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.
March 1, 2024

Yup, same for me. I couldnt find any endpoints in DC which will let us pass multiple ID at the same time. I will keep looking as well.

Of course, the single user endpoint works.

So, Depending on the importance of this rule for you, you could solve this in another (advanced) way.

Its complicated but I will explain.

We create a new rule, lets call this rule - compile emails and send email. This rule will recursively call itself until all users emails are gathered and send email in the end. The way it will work is:

Trigger = incoming webhook ( first call this webhook will receive is from your rule #1, see further below, with list of users from your initial rule in payload. From then on, this rule will call itself until needed).

You can do {{webhookResponse.body.users.first}} to reference say first user etc as always.

create a variable {{myemails}}

If Condition - Are there more users to gather? {{webhookResponse.body.users.size}} > 0

Action - Send webrequest to find 1 user using this end point

Store this email in {{myemails}} variable created earlier.  [Note - you have append not overwrite]

Next, Reformat original user list (that, revise users list you receive in payload to remove the recently gathered user) save it in a variable called {{revisedusers}} and

Action -  call same rule (this webhook rule endpoint) again, but with below payload.

{

"users": {{revisedusers},

"emails" : {{myemails}}

}

As you can see, as long as above If condition is satisfied, it will recursively call your list and gather emails. Your email list will be accessible as {{webhookResponse.body.emails}}

Finally in the end, you have another if condition when all users emails are gathered, that is, {{webhookResponse.body.users.size}} = 0 

Then you send email.

That completes your rule #2.

 

Now in your existing rule (rule 1), after you have compiled your users, you send a webrequest call to webhook from rule 2 with your payload as

{

"users": {{yourusers},

"emails" : ""

}

 

Def takes some time to set it up, I have done similar rules in the absence of advanced branching option in DC.

Hope it helps.

Harsh
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.
March 1, 2024

Hi @Kalyan Sattaluri 

It is a bit complicated and confusing too. 
But will try whatever i have understood and update you back.
Thank you for your time and the detailed explaination.

Suggest an answer

Log in or Sign up to answer