Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How do you get a web request to work in an automation rule?

Tim Bonney
Contributor
June 19, 2024

I am trying to build what I thought would be a simple automation rule with a web request to obtain the email addresses of the members of a project role (to be used in a later step of the same rule to send that group an email message). Nothing I try works and I have been unable to find the resolution through my own research, so I am hopeful that someone here has experienced the issue and can provide guidance.


I have formatted the request as follows:

URL: https://<OURCOMPANY>.atlassian.net/rest/api/3/project/10019/role/10005/members

Method: GET

Body: {} Empty

Delay execution: Checked

Header: Content-Type = application/json


However, when I provide an issue key from that project and attempt the validate button, it fails with a 404 not found Response and tells me the fist one below in the Response Payload:

If I take the "members" off the end and try, it, it tells me the project is not found, but I know for a fact that I am using the proper project id and role id, which I've shown as the second one below.

(* NOTE - I also tried both versions using project key instead of project id, but that gives the same results.)

 

{
  "message": "null for uri: https://jkseva.atlassian.net/rest/api/3/project/10019/role/10005/members",
  "status-code": 404
}

 

{
  "errorMessages": [
    "No project could be found with id '10019'."
  ],
  "errors": {}
}

2 answers

0 votes
Tim Bonney
Contributor
June 28, 2024

Thanks @Jovin

I tried this though, but am still getting a 404 error. Any further suggestions? Thanks.image.png

Jovin
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 28, 2024

Hey @Tim Bonney 

Cool I see the issue here with that screenshot! I should have asked for one earlier.

  1. You need to type in the Key/Value for every header, including the Content-Type, so make sure you have:
    1. Key: Content-Type
    2. Value: application/json
      1. It won't accept capitalized like in the example
  2. I couldn't find the end-point you're trying to query, but I can see you want the members email addresses of the project role, so here would be the API you want to query: https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-project-role-actors/#api-rest-api-3-role-id-actors-get 
    1. Actors are members in this regard, but it also returns the groups, so it will not necessarily always be returning you members
    2. For this case you'd need to then work through with some "for each" looping on the resulting data to essentially go:
      1. IF group THEN
      2. API call for members of group using this end point: https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-groups/#api-rest-api-3-group-member-get 
      3. IF user THEN
      4. you have the user

Let me know if anything else is unclear; I've not worked on the iterating over the returned data but give it a shot and if you get stuck I can try take a look later.

See below a screenshot of my config working with appropriate authorization & content-type headers:

api.png

Tim Bonney
Contributor
June 28, 2024

Thanks again @Jovin but even after changing application/json to lower case, I am still getting 404 error...

Jovin
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 30, 2024

Hey @Tim Bonney 

Don't forget to change the URL you're using as well. The one you have looks to not exist and the correct ones (get members of a project role) was also linked above.

If you're still having issues send through a new screenshot and we'll troubleshoot some more!

Tim Bonney
Contributor
July 1, 2024

Hi @Jovin .

Thanks again for all your guidance. When I use the url: https://xyz.atlassian.net/rest/api/3/role/10005/actors, I get a successful response, with a payload of actors, but no actual actors are listed:

{
  "actors": []
}

When I use the full url you provided previously, it still gives me a 404 (https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-project-role-actors/#api-rest-api-3-role-id-actors-get), but I am pretty sure that is because I am supossed to modify the part of the string following the "/rest/v3" with different text specifying my distinct values, but no iteration of that that I have tried works.

So, if I have the basic "actors" call working (but with empty results), what do I now need to change in order to further designate the specific project for which I want to identify the actors associated with that project role?

Thanks again for you guidance! This assistance is GREATLY appreciated.

Jovin
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 1, 2024

Hey @Tim Bonney 

On the right track! That URL that gives you no actors is the correct usage, glad we got it authenticated and working. That other URL I provided was simply the documentation so you're on the right track here.

I was off-track though; I gave you the find default actors for the project role, my bad! The correct one you want would be: https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-project-roles/#api-rest-api-3-project-projectidorkey-role-id-get 

You just need to change your URL that you're point to in your automation to:

/rest/api/3/project/{projectIdOrKey}/role/{id}

The automation I suggested to iterate over the data would need tweaking to get where you want, but should help provide some basic sguidance! 

Tim Bonney
Contributor
July 1, 2024

Thanks again @Jovin 

Looks like it was the "/members/" on the tail of my url string that was causing issues.

Now, I'll need to work on the parsing as you suggested, but I may need additional call(s) first because the actor content returned does not include email address.

I'm not sure I'll get the time to work on this today or tomorrow, but whenever I do, I will update this thread to let you know the outcome.

Thank you once again for all your assistance in this process. I really appreciate your willingness to help out a newbie. 

Like Jovin likes this
Jovin
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 1, 2024

All newbies at some point! Hopefully you've got what you need to keep playing around!

0 votes
Jovin
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 19, 2024

Hey Tim,

Have you tried replacing the 10019 with the key of the project? (e.g. if the issue key is KEY-123 your project key is KEY)? It looks like it's having issues with the numeric id.

Tim Bonney
Contributor
June 19, 2024

Hi Javin.

Yes, unfortunately, I have attempted it both ways but get the same results with either approach.

Rupa Goyal June 27, 2024

Was any solution found for this? I am facing the same issue.

Tim Bonney
Contributor
June 27, 2024

Sorry Rupa, but no. I am still struggling to figure out why it is happening. As you can see here, I only received one response to this post, but they had misread my original post.

Rupa Goyal June 27, 2024

Hey Tim, using a new API key worked for me.
Encoded it using: 
echo -n user@example.com:api_token_string | base64

Tim Bonney
Contributor
June 27, 2024

Thank you Rupa. I can try that, but am not sure what you mean...So, from my original post, in the URL string, I would replace "/api/3/", with "/api_token_string | base64"?

Rupa Goyal June 27, 2024

The change will be in the Authorization Header.

Jovin
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 28, 2024

Ah @Tim Bonney 

I see now - I missed a key thing, you didn't add the Authorization header into the parameters as well.

@Rupa Goyal is correct, you need to create an API key and then encode it as Base64. If you're windows based like me you can follow these:

$Text = "email:token"
$Bytes = [System.Text.Encoding]::UTF8.GetBytes($Text)
$EncodedText = [Convert]::ToBase64String($Bytes)
$EncodedText
  •  Copy that text that is output and put it into one of the headers in your automation, so you headers should be:
    • Content-Type
      • application/json
    • Authorization
      • Basic BASE64TOKEN

Hopefully that helps!

Tim Bonney
Contributor
June 28, 2024

Thank you @Jovin .

I appreciate both yours and @Rupa Goyal 's assistance!

I apologize for so many questions, but I am still a beginner here.

I think I understand what you are saying. However, with regards to the API token, we are using Jira Cloud, so do I still attempt the process you've indicated, even though this would not be on a local server? I ask because when you say "...via PowerShell on Windows you can ...", it makes me think I am doing this process locally, so am not sure this still applies if our jira instance is in the cloud.

Thanks.

Jovin
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 28, 2024

No worries at all, @Tim Bonney , it gave me headaches when I started with APIs too!

So, the API generation is done via the instructions and that's on your Cloud instance. You copy down that API token and do the PowerShell part on your local machine, if you don't have PowerShell, you could try find alternatives for macOS or others by googling "how to encode string as base64".

I wouldn't recommend doing an online tool for it just in case there's a possible security issue!

Then you can input that information into your automation rule, see an example screenshot below:

headers.png

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events