|
| 1 | +--- |
| 2 | +layout: default |
| 3 | +permalink: /examples/repositories/webhooks.html |
| 4 | +title: WebHooks |
| 5 | +--- |
| 6 | + |
| 7 | +# WebHooks |
| 8 | + |
| 9 | +This resource manages webhooks on a repository. The administrators of the repository are |
| 10 | +the only users who can create, access, update, or delete the webhook. |
| 11 | + |
| 12 | +### Prepare: |
| 13 | + |
| 14 | +```php |
| 15 | +$uuid = '30b60aee-9cdf-407d-901c-2de106ee0c9d'; // unique identifier of the webhook |
| 16 | +$hooks = new Bitbucket\API\Repositories\Hooks(); |
| 17 | + |
| 18 | +$hooks->setCredentials( new Bitbucket\API\Authentication\Basic($bb_user, $bb_pass) ); |
| 19 | +``` |
| 20 | + |
| 21 | +### Get a webhook: |
| 22 | + |
| 23 | +```php |
| 24 | +$hooks->get($account_name, $repo_slug, $uuid); |
| 25 | +``` |
| 26 | + |
| 27 | +**HINT:** You can use `$hooks->all()` method to get a list of all available hooks and their unique identifiers. |
| 28 | + |
| 29 | +### Get a list of webhooks: |
| 30 | + |
| 31 | +```php |
| 32 | +$hooks->all($account_name, $repo_slug); |
| 33 | +``` |
| 34 | + |
| 35 | +### Create a new webhook: |
| 36 | + |
| 37 | +```php |
| 38 | +$hook->create($account_name, $repo_slug, array( |
| 39 | + 'description' => 'Webhook Description', |
| 40 | + 'url' => 'http://requestb.in/xxx', |
| 41 | + 'active' => true, |
| 42 | + 'events' => array( |
| 43 | + 'repo:push', |
| 44 | + 'issue:created', |
| 45 | + 'issue:updated' |
| 46 | + ) |
| 47 | +)); |
| 48 | +``` |
| 49 | + |
| 50 | +**HINT:** For a full list of available events, see [Event Payloads](https://confluence.atlassian.com/display/BITBUCKET/Event+Payloads) page. |
| 51 | + |
| 52 | +### Update a webhook: |
| 53 | + |
| 54 | +Add a new event `pullrequest:approved` to our webhook: |
| 55 | + |
| 56 | +```php |
| 57 | +$hook->update($account_name, $repo_slug, $uuid, array( |
| 58 | + 'description' => 'Webhook Description', |
| 59 | + 'url' => 'http://requestb.in/xxx', |
| 60 | + 'active' => true, |
| 61 | + 'events' => array( |
| 62 | + 'repo:push', |
| 63 | + 'issue:created', |
| 64 | + 'issue:updated', |
| 65 | + 'pullrequest:approved' |
| 66 | + ) |
| 67 | +)); |
| 68 | +``` |
| 69 | + |
| 70 | +**HINT:** Bitbucket doesn't offer a patch endpoint, so you need to send the entire object represensation in order to update. |
| 71 | + |
| 72 | +### Delete a webhook: |
| 73 | + |
| 74 | +```php |
| 75 | +$hook->delete($account_name, $repo_slug, $uuid); |
| 76 | +``` |
| 77 | + |
| 78 | +---- |
| 79 | + |
| 80 | +#### Related: |
| 81 | + * [Authentication]({{ site.url }}/examples/authentication.html) |
| 82 | + * [BB Wiki](https://confluence.atlassian.com/display/BITBUCKET/webhooks+Resource) |
0 commit comments