Pipedrive Webhook PHP endpoint code example

353 views Asked by At

I have setup a webhook from Pipedrive to activate on a deal being updated. I am struggling with the correct way to read the json response in php. I am new to Webhooks so is there another way of reading the response data. This is what I have:

    <?php
    $result = $_REQUEST['current'];  // this is where it is not working I believe
    $obj = json_decode($result, true);
    $txt = $obj['id']
    $myfile = fopen("newfile.txt", "w") or die("Unable to open file!");
    fwrite($myfile, $txt);
    fclose($myfile);

In requestbin I am getting a response with all the correct information I am expecting

It appears that body of the event contains an array called "current" with all the relevant data in and I wanted to extract the "id" to see it working

    "body": {
           "current": {
            "id": 71}

Any help really appreciated

1

There are 1 answers

0
IMO On BEST ANSWER

I have found an answer that shows me what I require

$result = file_get_contents("php://input");

This pulls back the full response from the server showing data