Creating a webhook trigger add on when issue transitions to a state in Jira Service Management Cloud

Hi,

I want to create an add on to trigger actions in Bitbucket or Jenkins whenever issues transitions to a specific state in Jira Service Management.
I have done the initial set up using https://developer.atlassian.com/cloud/jira/platform/getting-started-with-connect/ and trying to register webhook for state changes. But adding webhook module in descriptor and REST API both failed.
I am new to Atlassian. I will really appreciate if I can get some some guidance if this is the right approach ?
Any help is appreciated!!

Thanks
Kind Regards,
Srishti

@SrishtiSuman welcome to the Atlassian developer community.

The webhooks modules for Connect only work for paths under the Connect App’s base URL. In short, they are for webhooks to the App itself. They are also static, in the sense the paths cannot be changed at runtime. Between the 2 constraints, you can’t use Connect webhook module directly but you could have your App act as a proxy. The app receives the webhook and then forwards to the configured Bitbucket or Jenkins URL. Your App is responsible for the aspects of that request, like maybe adding any authentication needed.

Registering the webhook through the REST API is for dynamic scenarios where the URL is not known by the App a priori. This might be a good fit for your use case, so your App doesn’t have to do webhook proxying. Can you explain more how the webhook-via-REST-API failed?

Hi @ibuchanan , Thanks for your response.

I have created a UI form as main page of my app. And I want to register a webhook when the form is submitted. I am calling a function onSubmit of the form. But I see below error message.

Error Message: “Access to fetch at ‘https://appnovationrnd.atlassian.net/rest/webhooks/1.0/webhook/’ from origin ‘https://***.ngrok.io’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. If an opaque response serves your needs, set the request’s mode to ‘no-cors’ to fetch the resource with CORS disabled.”

API endpoint : “https://appnovationrnd.atlassian.net/rest/webhooks/1.0/webhook/

I have tried adding Access-Control-Allow-Origin:"*" in the headers. But I am still getting the same error.

Thanks
Srishti

@SrishtiSuman,

From the error message, I see the path you are trying to use is one that doesn’t work for Connect Apps. Sadly, this is not clear from the documentation for these “other integrations”. Your App should be able to dynamically register the webhook using POST /rest/api/2/webhook. I’m pretty sure the docs also neglects to remind readers that clients must use the JWT bearer header, as is generally required for making API requests.

The docs are clear on the subset of capabilities on this API:

Limitations apply to the REST API in order to guarantee stability and performance of Jira Cloud for all apps and users.

Specifically, your App will be working with a subset of all available events and JQL query elements, with a max of 100 webhooks, and an expiration period that requires refreshing.