Handre Elias
Handre Elias

Reputation: 61

Bitbucket webhook not sending payload

I'm new to webhooks and trying to do automated deployment to my website whenever I push to my repo.

I set up the webhook on my bitbucket repo to a URL which contains a simple php script:

if(isset($_POST['payload'])) {
    logMsg("Got stuff\n");
} else {
    logMsg("No stuff\n");
}

After I push to my repo, the webhook will request the script fine but no payload is sent. My log file will always say "No stuff".

What am I missing?

Upvotes: 5

Views: 2443

Answers (2)

Zebratrois
Zebratrois

Reputation: 51

The new Bitbucket webhooks send the payload in the request body, not in the request headers as the previous "Services" did. So to access the payload you must read the request body like this :

$payload = file_get_contents('php://input');

or like that:

$payload = stream_get_contents(STDIN);

Et voilà !

Upvotes: 5

VonC
VonC

Reputation: 1323223

BitBucket webhook changed recently (June 2015).

The new event payload doc refers to a tutorial page whose example does not test for payload.
See atlassianlabs/webhook-listener and its listener.py (python, but the idea would be the same for php)

@app.route('/webhook', methods=['GET', 'POST'])
def tracking():  
    if request.method == 'POST':
        data = request.get_json()

It tries directly to decode json. If that json data were to be empty,... that would mean no payload.

Upvotes: 0

Related Questions