Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

how to set secret in bitbucket webhook api call ?

Sagar Sukdev Navale May 17, 2023

i created bitbucket webhook api call supplied it with secret the secret token not generate.how to set secret ?. i have use requests methods

def create_hook(workspace_id):
    # Build the URL for the workspace webhooks endpoint
    url = f'https://api.bitbucket.org/2.0/workspaces/{workspace_id}/hooks'

    auth = ("user_name", "password")
    data = {
        'url': 'https://demourl.com',
        "name": "wehhook test secret",
        "description": " new webhook test ",
        'active': True,
        'events': [
            "pullrequest:approved", "repo:commit_comment_created",
        ],
        "configuration": {
            "secret": "abcdef",

        }

    }
     # end the HTTP request to create the webhook
    response = requests.post(url, json=data, auth=auth)
    if response.status_code == 201:
        return response.json()
    else:
        print("failed to create webhook", response.text)
        return {}```

 

i want to secret token will generated ,how add secret in bitbucket webhook

2 answers

1 accepted

0 votes
Answer accepted
Aron Gombas _Midori_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 18, 2023

There are multiple ways to authenticate to the Bitbucket Cloud REST API, but I think the easiest for you is using BASIC auth with an app password.

As a best practice, you should not encode the app password to your script, but store that in a Bitbucket repository secret.

0 votes
Patrik S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 18, 2023

Hello @Sagar Sukdev Navale ,

Welcome to Atlassian Community!

My understanding is that you are trying to create a webhook using the API endpoint Create a workspace webhook , and you would like to set a secret to this webhook. I'm afraid that currently, secrets are not available in Bitbucket Cloud webhooks, and this is the reason you are not being able to create a webhook with secrets using the API.

We do have an open feature request to implement secrets functionality to webhook, which you can check in the following link: 

I would suggest you to add your vote there, since this helps both developers and product managers to understand the interest. Also, make sure you add yourself as a watcher in case you want to receive first-hand updates from that ticket. Please note that all features are implemented with this policy in mind.

You're also welcome to take a look at Bitbucket Cloud API reference to check the options available for the create webhook endpoint : 

Thank you, @Sagar Sukdev Navale !

Patrik S

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events