feat: cli command to un-/register MailJet webhook url

This commit is contained in:
Björn Fromme
2026-04-29 10:36:04 +02:00
parent daf89f9189
commit a2bcedafc4
5 changed files with 349 additions and 1 deletions
+39 -1
View File
@@ -119,6 +119,28 @@ class MailjetApiClient
}
}
/**
* @return array<string, mixed>
*/
public function createEventCallbackUrl(string $eventType, string $url, int $version = 2, bool $isBackup = false): array
{
return $this->request('POST', 'eventcallbackurl', [
'json' => [
'EventType' => strtolower(trim($eventType)),
'Url' => $url,
'Version' => $version,
'isBackup' => $isBackup,
],
]);
}
public function deleteEventCallbackUrl(int $eventCallbackUrlId): void
{
$this->request('DELETE', sprintf('eventcallbackurl/%d', $eventCallbackUrlId), [
'allow_empty' => true,
]);
}
private function findOrCreateContactId(string $email): int
{
$contactId = $this->resolveContactId($email);
@@ -223,7 +245,9 @@ class MailjetApiClient
private function request(string $method, string $resource, array $options = []): array
{
$allow404 = true === ($options['allow_404'] ?? false);
$allowEmpty = true === ($options['allow_empty'] ?? false);
unset($options['allow_404']);
unset($options['allow_empty']);
$resourcePath = trim($resource, '/');
@@ -241,7 +265,21 @@ class MailjetApiClient
return [];
}
$payload = $response->toArray(false);
$content = $response->getContent(false);
if ('' === trim($content)) {
if (true === $allowEmpty && $statusCode < 400) {
return [];
}
throw new NewsletterProviderException(sprintf('Mailjet request returned an empty response for resource %s', $resource));
}
try {
$payload = json_decode($content, true, 512, JSON_THROW_ON_ERROR);
} catch (\JsonException $exception) {
throw new NewsletterProviderException(sprintf('Mailjet request error for resource %s', $resource), previous: $exception);
}
if ($statusCode >= 400) {
$payloadSummary = json_encode($payload, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
$payloadSummary = false === $payloadSummary ? null : $payloadSummary;