Skip to end of metadata
Go to start of metadata

Repository administrators can add a Pull Request POST hook to a repository. Bitbucket POSTs pull request event data to a hook URL you specify.  You specify a URL in the format:

Bitbucket supports HTTPS and basic authentication.  When configuring the pull request POST hook, you can choose to get event data about the following:

EventDescription
Approve / UnapproveFires when user sets or unsets Approve for a pull request.
CommentsFires when a user creates, edits, or deletes a pull request comment.
Create / Edit / Merge / DeclineFires when a user creates, edits, merges, or declines a pull request.

The content header of the POST has an application/json type. This hooks behave similarly to an HTTP publish/subscribe hook. The payload is a json document.

The POST request originates from the IP addresses 131.103.20.165 and 131.103.20.166. You may need to configure your firewall to accept connections from these IP addresses.

Configure the Pull Request POST hook

You can set up the POST hook manually or you can write a hook to automate this. You would write a hook if you are integrating an application with Bitbucket. 

Manually configure from the repository administration page

  1. Go to the repository's  settings.
  2. Click Hooks in the left-hand navigation.
    The Hooks page appears.
  3. Select the Pull Request  POST hook from the Hook dropdown.
  4. Click Add hook.
    A new section appears for the POST hook.
  5. Enter the URL where Bitbucket should send its update messages.

  6. Choose the pull request events you are interested in by checking the corresponding box.
  7. Press Save.

Automatically configure the URL from another application

If you are integrating with Bitbucket and looking for an easy way to add the hook for your users, there are two methods you can use to automate this.  You can send the user to a URL structured in the following way:

If you're using OAuth or passing through basic authentication, you can use the api to accomplish this as well

 

Examples of POST data

When a user makes pull request's against a repository, Bitbucket POSTs to the URL you provided. The POST request body contains information about the pull request change. 

Examples

Approval  Expand source
Comment Created  Expand source
Comment Deleted  Expand source
Comment Updated  Expand source
Created  Expand source
Merged  Expand source
Declined  Expand source
Approve unset  Expand source
Updated  Expand source
If you are having trouble, please see Troubleshooting Bitbucket services.

17 Comments

  1. Is it possible to add the pull request link/name/info that was approved to pullrequest_approve?

    1. There's an issue that is tracking that: https://bitbucket.org/site/master/issue/8340/pull-request-post-hook-does-not-include

      You might want to put a watch on that for progress updates.

      1. I commented the issue, but no one from atlassian seems to have commeted it since the beginning. Any way to gather some sort of feedback ?

  2. Even some of us are paying for Bitbucket services, there is no echo from them.

    Simple things like hooks could not be completed and fully working. And priorities on those are "trivial" although CI could not be incorporated because of bugs. If no CI no development equals "Major" priority issue.

    1. Good day Marko,

      Thank you for taking time to comment.

      I think the issues which are marked "trivial" are not things which are causing the full site (including git command line functions push / pull / clone etc). When you notice a site or functional outage the best place to follow what's happening is the Bitbucket status site where you can see regular updates to resolve an issue. We are very aware when these occur and they are treated as critical issues which are addressed as quickly as possible. 

      Additionally, if you exprience an outage which is not registered on the status page please contact support so they can help you and track any issues.

      We are always working to be sure site outages do not happen but if they do we want to get you back to your projects as quickly as possible.

      1. Hi Dan,

        I can "see" that your answer is pretty close to copy paste letter, and obviously you did not understand what I commented. We are commenting in Pull Request Hook.

        So please connect the dots.

        1. Hi Marko,

          Yes I misunderstood your comment, I mistook what you said as meaning you were getting no response from command line functions. I ran through a couple tests of this hook and was able to get it working. I will pass your comment on to the support team and, if you haven't already,  please contact them directly support@bitbucket.org.

          Dan

           

          1. Hi,

             

            Thank you for considering my thread again. I can successfully use the PULL request HOOK, but thing that it is not working okay, or I misunderstood the concept of it.

            Lets say I want to use PULL request hook only when pull request is created, and I dont care if comments are added or it is aprooved or declined. I want my CI to be triggered only on pull request create/edit/delete/update.

            Currently this does not work.

  3. Dan, maybe I can point you to this issue which seems to have a lot of people growling, because it is essential to a fully working CI : https://bitbucket.org/site/master/issue/8340/pull-request-post-hook-does-not-include

    1. Hey,

      I'm watching this issue now and will update the doc's as soon as we have some movement. I don't know where we are with this but I know we do "hear" everyone on this.

      Thanks for taking time to comment. (smile)

       

  4. I would like to request a proper integration with slack.com
    I have tried the generic integration with slack that uses the  Pull Request POST, but it doesn't work when a new pull request is created.

    1. Hey Javier,

      I've looked for an existing issue but didn't find one for what your requesting. Can you open an enhancement request at https://bitbucket.org/site/master/issues

      (smile)

      Thanks,

      Dan

        1. Thank you, for taking time to make us better!

           

  5. I have written this integration myself, in Node: https://github.com/lfilho/bitbucket-slack-pr-hook

    Too bad the api itself is not yet finnished. Many important fields are missing from pretty much all endpoints that are not the "created" one.

  6. Why does the 'id' value appear only in 'pullrequest_created'? Can we get the pull-request's 'id' in all types of payloads please?