Webhooks get body

Brahim ESSALIH November 7, 2016

Hello everybody, 

I'm trying to use JIRA webhooks, I need to get the JSON body send by JIRA when when an issue has been updated and get the field which is updated.

is it that possible ?

This is a snippet of my descriptor.json

"webhooks": [
			{
				"name": "Hello webhook",
				"event": "jira:issue_updated",
				"url": "/test",
				"excludeBody": false
			}
		]

 

 Best regards

2 answers

1 accepted

4 votes
Answer accepted
Jon Bevan [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 7, 2016

Hi @Brahim ESSALIH,

If you hadn't found it already this page is useful: https://developer.atlassian.com/jiradev/jira-apis/webhooks#Webhooks-Example:callbackforanissue-relatedevent

What that page says is that during an issue_updated event you should receive a changelog property in the JSON body that contains the description of what changed most recently. The example on that page shows the changelog property looks like:

"changelog": {
        "items": [
            {
                "toString": "A new summary.",
                "to": null,
                "fromString": "What is going on here?????",
                "from": null,
                "fieldtype": "jira",
                "field": "summary"
            },
            {
                "toString": "New Feature",
                "to": "2",
                "fromString": "Improvement",
                "from": "4",
                "fieldtype": "jira",
                "field": "issuetype"
            }
        ],
		"id": 10124
},

I guess if more than on field changed, then the "items" array will contain more than one entry.

Hope that helps, Jon

Brahim ESSALIH November 7, 2016

Thanks @Jon Bevan [Adaptavist]. Can I tell JIRA to send me the key or id of the field too because the name is not very significant. I need to khow what is the id/key of custom field which is has been updated

 

Best regards 

Jon Bevan [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 7, 2016

The "field" property contains the field's key if I remember right. So for a custom field it'll be something like "customfield_10931" but for system fields its "summary" or "issuetype" etc

Brahim ESSALIH November 7, 2016

this is the response when I update a costom field

 

"changelog": {
		"id": "27368",
		"items": [
			{
				"field": "Adresse de facturation",
				"fieldtype": "custom",
				"from": null,
				"fromString": "8 lotissement Darbousson",
				"to": null,
				"toString": "8 lotissement Darbousson\r\nhdfgf"
			}
		]
	}
Jon Bevan [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 7, 2016

That's annoying! In that case you'll need to use the fields REST API (https://docs.atlassian.com/jira/REST/cloud/#api/2/field-getFields) to retrieve the available fields and then filter through those for the one that matches the name (assuming you don't have duplicate field names).

Here is Atlassian's publicly visible bug report to fix this which you can vote on and watch: https://ecosystem.atlassian.net/browse/ACJIRA-955

Brahim ESSALIH November 7, 2016

ok Thanks @Jon Bevan [Adaptavist]

0 votes
kz1212 October 5, 2017

Hi @Jon Bevan [Adaptavist],

I am using jira-python in windows, and I want to try to set up the webhook. Do you have any tutorial that can guide me through? thanks!!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events