Call Jira REST API from Jira Plugin

Hello, I hope you can help…

I have a use case:

  • Each time an issue is Created or Updated, search for specific custom fields and get the values of those specific custom fields, then call a Jira REST API to do something with those values.

  • I am writing a Jira plugin, it has an event listener.

  • With this listener, I know when any issue is created or updated, etc.

  • When an issue is created or updated, I can get that issue and the fields via the Java API.

  • This all works.

But I subsequently want to call the ‘issue entity’ REST API with the issue that was just created/updated**.

No examples I’ve seen online seem to work for me using SAL, because when I run ‘atlas-package’, it fails on
import com.atlassian.sal.api.net.TrustedRequest;
import com.atlassian.sal.api.net.TrustedRequestFactory;

However, ‘atlas-package’ compiles successfully using:
import com.atlassian.sal.api.net.RequestFactory;

So should I be using SAL and just RequestFactory? or do I need the TrustedRequestFactory?

Code samples are welcome! I feel it’s a really easy thing to do and I’m somehow missing it.

Again, I just want to call Jira REST API from Jira Plugin installed on the same instance - and be authenticated/permitted to do a PUT/GET using ‘jira entities’ on the issue just created.

Thank you

1 Like

Hi @DCH,

Thanks for your post. A few ideas to get you started, and one gotcha. I’d like to check first, you’ve linked to the REST API for Jira Cloud not Jira Server. Jira Server/DC REST APIs are documented in

The REST API you’re hoping to use isn’t available in Jira Server.

Depending on how you are making the request to the REST endpoint, if it’s not in an Authenticated thread, you won’t have a local user to make the request under.

Over in Atlassian Community someone asked the same question

The trick is, for getJiraAuthenticationContext().getLoggedInUser() if you are running this from a thread outside of a user request like an EventListener, you might not have a logged in user, so the authentication will fail.

Is there a reason you want to do it with REST API and not Java API? You might be able to use something like

Regards,
James.

1 Like

Thank you @jrichards, yes, I meant the DC api link above, not cloud, thanks for noticing.

Thank you also for suggesting IssuePropertyService, I think that will do what I need. I was in a “rest api mindset” and didn’t think the Java API provided this feature/class. Silly me. I still have to try this but thank you for bringing this to my attention!

2 Likes