I've tweaked the code and I think I'm getting closer to the solution, but still receiving an error.
public function onPluginsInitialized()
{
$this->add_member();
}
public function add_member() {
require __DIR__.'/vendor/autoload.php';
$url = 'url';
$api_key = 'api_key';
$list_id = 'list_id';
$client = new \GuzzleHttp\Client();
$result = $client->request('POST', $url.'lists/'.$list_id.'/members', [
'headers' => [
'Authorization' => 'apikey '.$api_key,
'json' => [
'email_address' => $_POST['email'],
'email_type' => 'html',
'status' => 'subscribed'
]
],
'verify' => false,
'debug' => false
]);
}
Here's the error I'm getting:
'Undefined index: email' Where shall I define email? How to catch it from the form?
I tried to follow this example. However, my syntax is different. I shall add that the reason for my syntax is dictated by the fact that I'm trying to create a plugin for GRAV, also using Guzzle.