Search code examples
phpwebhooksplaid

PHP script for Plaid webhooks


I've set up an account to try out and one of the most interesting part of their API is the webhooks. However, I haven't found a reference to how to 'catch' the webhooks using a PHP script. I imagine that it is something like:

<?php
//pseudo-ish code
$webhook = $_POST['webhook'];
$json = json_decode($webhook, true);

// code to save webhook data

Anyone have any ideas? Here is the link to their API

Per a comment, I tried:

<?php
$result = var_export($_POST, true);
$file = fopen("screenshots/test.txt","w");
echo fwrite($file, "testing:".$result);
fclose($file);
?>

and all that results is a file with the word "testing:array()" in it indicating that $_POST is empty.


Solution

  • The API sends the payload as a JSON encoded string in the body of the request.

    $data = json_decode(trim(file_get_contents('php://input'), '"\''), true);