<?php
ini_set('display_errors',1);
ini_set('display_startup_erros',1);
error_reporting(E_ALL);

require_once('vendor/autoload.php');
$client = new \GuzzleHttp\Client();

$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => "https://api.pluggy.ai/auth",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => json_encode([
    'clientId' => '83f8fd2e-56fc-47af-add3-6dd003d904d5',
    'clientSecret' => 'a0bf2c68-eed3-47d4-9b05-38fd42a9e0e1'
  ]),
  CURLOPT_HTTPHEADER => [
    "accept: application/json",
    "content-type: application/json"
  ],
]);

$retorno = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);


$json01 = $retorno;


$json02 = json_decode($json01);

$apiKey = $json02->apiKey;

echo $apiKey;
echo "<br><br>";

$response = $client->request('GET', 'https://api.pluggy.ai/webhooks', [
  'headers' => [
    'X-API-KEY' => $apiKey,
    'accept' => 'application/json',
  ],
]);

echo $response->getBody();



?>