You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
I'm attempting to create a webhook in Jira using Python and an OAuth 2.0 token for authentication. However, I'm encountering an error message, and I could use some guidance on how to resolve it.
Here's the Python code I'm using:
import requests
import json
def create_jira_webhook(project_key, oauth_token):
# Define the URL for creating a webhook in Jira
webhook_url = f"https://enviatetesting.atlassian.net/rest/api/3/webhook"
# Define the webhook payload
webhook_payload = {
"name": "Your Webhook Name",
"url": webhook_url,
"events": ["jira:issue_created", "jira:issue_updated", "jira:issue_deleted"],
"properties": {
"jqlFilter": f"project={project_key}"
}
}
# Defining the headers with OAuth 2.0 token
headers = {
"Authorization": f"Bearer {oauth_token}",
"Content-Type": "application/json"
}
# Send the POST request to create the webhook
response = requests.post(webhook_url, headers=headers, data=json.dumps(webhook_payload))
if response.status_code == 201:
print("Webhook created successfully.")
else:
print(f"Failed to create webhook. Status code: {response.status_code}")
print(response.text)
# Usage example
project_key = "KAN"
oauth_token = "your_oauth_token_here"
webhook_url = "https://your-webhook-url.com"
create_jira_webhook(project_key, oauth_token)
The error message I'm receiving is:
Failed to create webhook. Status code: 401
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<status>
<status-code>401</status-code>
<message>Client must be authenticated to access this resource.</message>
</status>
```
I've double-checked my OAuth token, and it seems to be correct. What could be causing this authentication issue, and how can I resolve it?
Any assistance or insights would be greatly appreciated. Thank you!
Hello @Satyajit,
Did you try with HTTP basic auth:
auth = HTTPBasicAuth("email@example.com", "<api_token>")
Add "auth" to your post request parameters.
And than remove your Authorization from headers, also add to "Accept": "application/json"
to headers.
Let me know if this helps.
Best regards,
Marko Blagus
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.