From fb567a4df9b4ed81a1b7b50ce27a2c593966d9a6 Mon Sep 17 00:00:00 2001 From: Roel van Duijnhoven Date: Thu, 14 Sep 2023 16:08:56 +0200 Subject: [PATCH] Allow previewing the actual Sparkpost template, not the draft. --- src/Service/SparkPostService.php | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/Service/SparkPostService.php b/src/Service/SparkPostService.php index b8da60b..89f7eb5 100644 --- a/src/Service/SparkPostService.php +++ b/src/Service/SparkPostService.php @@ -552,7 +552,12 @@ function ($error) { throw new RuntimeException('SparkPost server error, please try again'); } - public function previewTemplate(string $templateId, array $substitutionVariables = [], array $options = []): array + public function previewTemplate( + string $templateId, + array $substitutionVariables = [], + array $options = [], + bool $useDraftIfAvailable = true + ): array { $headers = []; @@ -566,9 +571,17 @@ public function previewTemplate(string $templateId, array $substitutionVariables 'substitution_data' => $substitutionVariables, ]; - $response = $this->prepareHttpClient(sprintf('/templates/%s/preview', urlencode($templateId)), $post, $headers) - ->send() - ; + $response = $this->prepareHttpClient( + sprintf( + '/templates/%s/preview?%s', + urlencode($templateId), + http_build_query([ + 'draft' => $useDraftIfAvailable ? 'true' : 'false', + ]), + ), + $post, + $headers + )->send(); return $this->parseResponse($response)['results'] ?? []; }