Jira has grown in popularity over the years and it is used by more 180,000 customers from more than 190 countries. It has listed products like Jira Software and Jira Work Management. Jira offers Webhooks an easy way to get real-time updates of data when there is an event triggered on a ticket. In this article, you will learn the basics of Jira Webhooks and how you can use them to get updates on tickets.
What is a Webhook?
A Webhook is a way to modify the behavior of web pages and web applications using custom callbacks. It is basically a user-definable HTTP callback that’s triggered by certain events. A Webhook is a type API that is driven more by events than requests. Instead of an application asking another program to send a reply, a Webhook allows a program send data to another program as soon as a specific event occurs as specified by the user. In the sense that an application initiates communication rather than receiving requests, they are called ” reverse APIs“.
You can use Jira webhooks in Jira to notify your web apps or web applications when certain events occur. This will allow remote applications to not have to poll Jira every so often to determine if there are any changes.
How to Set up Jira Webhooks?
Jira Webhooks typically contain the following information, which must be provided when creating a Webhook.
- Name. This is The name of the Webhook that was created in Jira.
- URL. This is the URL to which the callback will be sent after creation.
- Scope. This determines the Webhook’s scope. It can be all issues or just a set of issues as specified by JQL, such project =TEST and fixVersion=future.
- Events. This is the event that determines the posting of URLs when they are triggered. It can either be all events or a particular set of events.
Jira webhooks can be registered/created using one of the following methods.
- Create a webhook in Jira Administration console
- In the description of your Atlassian Connect App, declare a Webhook.
- Registering a webhook using the RESTAPI: Connect and Oauth 2.0 apps
- Registering a webhook using the RESTAPI: Other integrations
Create a Jira Administration Console Webhook
These steps will help you register a webhook using this method:
- Navigate to Jira’s administration console and navigate to System, then under the AdvancedSection, webhook.
- Click on create a webhook.
- Fill in the form to create your Webhook.
- To create your Webhook, click on create.
Registering Jira Webhooks with the REST API: Connect or Oauth 2.0 Apps
To register a webhook via REST, execute the POST in JSON format at the following URL /rest/webhooks/1.0/webhook
{
"name": "Jira Webhook Example",
"url": "http://www.demo.com/webhooks",
"events": [
"jira:issue_created",
"jira:issue_updated"
],
"filters": {
"issue-related-events-section": "Project = JRA AND resolution = Fixed"
},
"excludeBody" : false
}
The response will contain the Webhook in JSON along with additional information such as the creator of the Webhook and the created timestamp.
Managing Jira Webhooks
You will need to edit, delete, or disable your Webhooks in Jira to make changes. Below are two methods of managing Webhooks using Jira’s administration console or REST API.
You can manage Webhooks in Jira by using the administration console.
- Log in to Jira using your Administered Jiraglobal Authorization.
- Navigate to System by selecting Settings.
- In Advanced option, select
- To edit, delete or disable a Webhook, click the Summaryof the Webhook column. A Webhook can be deleted permanently, while a Webhook that is disabled will not fire.
To manage Jira Webhooks using the Jira API to Unregister (Delete), execute DELETE at the following URL.
/rest/webhooks/1.0/webhook/{webhook id}
curl --user username:password -X DELETE -H "Content-Type: application/json" /rest/webhooks/1.0/webhook/40
This example will delete a Webhook with ID 40.
To edit Webhooks using Jira’s REST API, use the PUT method at the following URL.
/rest/webhooks/1.0/webhook/{webhook id}
{
"name": "my first webhook via rest",
"url": "http://www.demo.com/webhooks",
"events": [
"jira:issue_created",
"jira:issue_updated"
],
"filters": {
"issue-related-events-section": "Project = JRA AND resolution = Fixed"
},
"excludeBody" : false
}
To query webhooks in Jira with the Jira REST API, type GET. To get a specific Webhook by its ID, execute GET to the following URL:
<JIRA_URL>/rest/webhooks/1.0/webhook
curl –user username:password -X GET -H “Content-Type: application/json” <JIRA_URL>/rest/webhooks/1.0/webhook/50
This example will generate a Webhook with an ID 50.
Automating Jira Webhooks
Application can respond to the conditions you have set. This means that an action is triggered when an event occurs, or a condition is met. You can use the Webhook to specify your action. This is how to set up an automation rule that will trigger a Webhook to notify the application.
- Navigate to Project Settings,
- Go to Automationand create a Custom Rule or edit an existing one.
- Set the WHENand IF settings according to your preference. Next, add a THEN Finally, choose Webhook.
- Set the Webhook setting to indicate your URL, payload, and name your rule. Save it.
Executing Jira Webhooks
A Webhook triggers by sending a request to JSON. This usually includes the Webhook ID, timestamp and, as well information about the entity that is associated with the event. Below is an example of a callback to be sent for an issue-related incident.
{
"timestamp"
"event"
"user": {
--> See User shape in table below
},
"issue": {
--> See Issue shape in table below
},
"changelog" : {
--> See Changelog shape in table below
},
"comment" : {
--> See Comment shape in table below
}
}
You can execute a Webhook in any of these ways:
- Request Method: Jira will send an HTTPPOSTrequest when a webhook THEN is triggered.
- Success Criteria & Timeout:A Webhook HTTP Post request is considered successful if the server returns a response with an HTML status code between 200 and 300.
- Asynchronous Webhook Execution:The Webhook THEN is executed asynchronously. If multiple executions need to be triggered within a short time, they are queued up and executed one by one without interfering with other automated rules that you have set in Jira.
How to add Jira Webhooks as a post function to a Workflow?
To make it easier to trigger Webhooks when an issue is in a workflow transition, Webhooks can also be attached to workflow post functions. You can add a Webhook to a workflow as a post function by following these steps:
- Navigate to workflow configuration and choose the desired transition from the workflow designer.
- Click Post functions, then select Add post function.
- Select Trigger a Webhook in the list of post functions, and then click add.
- To add the Webhook to a post function, select the desired Webhook from a list.
Conclusion
So that was all about the Jira Webhooks. Now you know how to manage, automate, and create Webhooks, among other operations on the JIRA software. You will now be able to understand the basics of Webhooks and how to use them to track events on Jira.