Listening to Jira events using javascript API

Hi,

I’m developing an add-on for jira cloud and need it to listen to some basic events like issue status change, comment added/edited/deleted . The problem is I can’t find any documentation on such events, could someone please point to the right place I can that info at? As far as I understood jira-addons use postMessage() to communicate with jira and each other, so I tried to add a message event listener to the add-on’s iframe, but it did not catch anything upon changing issue’s status or adding a comment.

Thanks.

1 Like

For a cloud app you can’t listen to events in an IFrame. You need to listen from a backing web service via a webhooks module: https://developer.atlassian.com/cloud/jira/platform/modules/webhook/

We have a Jira cloud app that presents a web part dependent on the content of the summary field. When the summary field is updated, our web part becomes out of date. (we do use a webhook to capture the change at the server end…) Do we need to write a Js polling to our server, in case the user has changed the summary field? This is likely to 10x server traffic…

I would recommend something more like a Pub/Sub architecture. But otherwise yes, at this point in time, if an App wants live updates in the iframe that it controls then it needs to implement its own mechanism.

If it helps, I’ve done something similar using Connect to funnel webhooks to a front-end via websockets. To do it, in a nutshell…

I added a webhook module in atlassian-connect.json

In my server instance, I run a node.js service that runs a WebSocketServer to keep track of client connections. The same server takes the webhooks and passes the payloads on to clients. Important note: My example code does not take enough care to authenticate information or decide where to pass it for production use. It should be possible to do that however.

In my client code iframe, a generalPage module, I have included code for establishing (and re-establishing) websocket connections, and relaying webhook payloads received via the websocket to the rest of my app code.

This isn’t particularly hardened nor well maintained sample code (it serves a single user, me, for a toy app), but hopefully helps get you on a good path!

1 Like

@RogerBarnes. this is a cool implementation - clever. It’s the kind of thing I was thinking about. I may have to look at this kind of complexity in due course. Thank you for sharing. If Jira could somehow publish the event of a field save/update, that would be a lot simpler.

Indeed, that would be nice. With the approach I have you need to inspect webhooks to decide whether you care about the specific change.

@RogerBarnes,
Even if it can gives a lot of fun to build :slight_smile:, instead of warming the planet a little bit more with a fullstack architecture dedicated to exchange browser messages between a document and its iframe , is there any plan for Atlassian to use some of the pieces they’ve already built: https://developer.atlassian.com/cloud/jira/platform/jsapi/events/ ?
The cross iframe event bus is here, why not just sending a set of events through it ? It looks much easier to trigger a set of events from the UI layer than building a backend stack, with webhook listener, web socket and so on, no ?

6 Likes

+1000 to what @JulienJulien said

7 Likes

For your use case I can see the advantage of doing that. I’ll run it by the team.

1 Like

+1000 to what @david2 said !

2 Likes

Hi!

I need to create listener for web element on customfieldedit screen. Could you help me please. I try to use useEffect fo them, but onChange in select field doesn’t track selected value

3 and half years later, any update?

Welcome to the Atlassian developer community @ColinHammond,

A lot has happened in 3 1/2 years, including the launch Forge, which makes your line of question very ambiguous. There are updates but we all need to better understand the current context of your needs. Could you start a new topic to ask a full question?

And, because so much has change, I’m going to close this thread in favor of future community members asking in a new topic too.