How can I register a webhook programmatically from a connected app?

stevan
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 13, 2024

Hi,

 

I created an app that uses oauth2 to ask for consent from the user in order to perform actions on their behalf.

I added the the following permissions and scopes as per Jira webhook API reference 

`read:fiield:jira`, `write:webhook:jira` and `read:project:jira`.

I successfully complete the oauth2 flow and obtain the token pair.

With the token I want to create a webhook using the API.

I tried using the token to get other resources and it's working. I am able to fetch the users issues and other resources.

I decoded the JWT on https://jwt.io and I see the correct scopes in the claims.

First I tried the official recommended way with the API token:

 

webhook_api_url = "https://my-instance.atlassian.net/api/rest/3/webhook"

headers = {
"Content-Type": "application/json",
"Accept": "application/json",
}

auth = HTTPBasicAuth("email@example.com", "my-api-token")

request = {
"url": "https://example.com",
"webhooks":[{"events": ["jira:issue_created", "jira:issue_updated"]}]
}



response = requests.post(webhook_api_url, headers=headers, json=webhook_data, auth=auth)

I get a `401`: `Client must be authenticated to access this resource.`

Then I tried using the Bearer token:

 

webhook_api_url = "https://api.atlassian.com/ex/{my-id}/rest/webhooks/1.0/webhook"

headers = {
"Content-Type": "application/json",
"Accept": "application/json",
"Authorization": f"Bearer {my-token}"
}

request = {
"name": "my webhook",
"url": "https://example.com",
"events": ["jira:issue_created", "jira:issue_updated"],
}



response = requests.post(webhook_api_url, headers=headers, json=webhook_data)

I get a `401`: `Unauthorized; scope does not match`.

Can someone help me with which request I am supposed to make?

2 answers

1 accepted

0 votes
Answer accepted
stevan
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 23, 2024

I solved it by giving my app the manage:jira-webhook classic permission.

It didn't work with the granular ones.

0 votes
marc -Collabello--Phase Locked-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 14, 2024

Hi @stevan ,

Maybe it's the "name" field in the webhook.  A name field is not defined in the documentation.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events