BitBucket Rest API, change repository settings

Viewed 29

So I have this repo: https://bitbucket.com/rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/ this URL outputs alot of information about the repository

repo

I then tried to create a Python script which featch this URL information:

import requests

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

response = requests.get('https://bitbucket.com/rest/api/1.0/projects/GGT/repos/GRP1/', headers=headers, auth=('USERNAME', 'TOKEN'))
print(response.text)

This prints out the same JSON stuff, as shown in the picture.

Now I know I have a connection to the repository. I then want to add a Webhook to this repo, but I cant seem to find out how to do this.

I tried to do something like this, but that doesn't work.

json_data = {
    'title': 'BitBucket_Webhook',
    'url': 'http://uua231z:5000/bitbucket',
    'enabled': 'true',
}

response = requests.put('https://bitbucket.com/rest/webhook/1.0/projects/GGT/repos/GRP1/configurations', headers=headers, json=json_data, auth=('USERNAME', 'TOKEN'))
print(response)

How can I add a webhook to a repository, can't seem to find that much on the internet on how this could be possible?

I tried this from the comments

headers = {
    # Already added when you pass json= but not when you pass data=
    # 'Content-Type': 'application/json',
}

json_data = {
    'title': 'BitBucket_Webhook2',
    'url': 'http://test123:5000/bitbucket',
    'enabled': 'true',
}

# Found here: https://docs.atlassian.com/bitbucket-server/rest/4.1.0/bitbucket-rest.html
response = requests.put('https://bitbucket.com/rest/api/1.0/projects/GGT/repos/grp1/webhooks', headers=headers, json=json_data, auth=('USERNAME', 'TOKEN'))
print(response)

But I get <Response [405]>

1 Answers
Related