Skip to content

Commit

Permalink
Allow previewing the actual Sparkpost template, not the draft.
Browse files Browse the repository at this point in the history
  • Loading branch information
roelvanduijnhoven committed Sep 14, 2023
1 parent dcef5ae commit fb567a4
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/Service/SparkPostService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];

Expand All @@ -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'] ?? [];
}
Expand Down

0 comments on commit fb567a4

Please sign in to comment.