Skip to content

Commit

Permalink
Merge pull request #149 from nickvanderveeken/feature/render-template
Browse files Browse the repository at this point in the history
Add method to SparkPostService to preview a template
  • Loading branch information
roelvanduijnhoven authored Nov 1, 2021
2 parents 4ce23f3 + baace04 commit e87a884
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Service/SparkPostService.php
Original file line number Diff line number Diff line change
Expand Up @@ -505,4 +505,19 @@ function ($error) {
// There is a 5xx error
throw new RuntimeException('SparkPost server error, please try again');
}

public function previewTemplate(string $templateId, array $substitutionVariables = []): array
{
// Request: POST/api/v1/templates/{id}/preview{?draft} ; with POST body given as JSON: { "substitution_data": { "key1": "value1", "key2": "value2" } }
// Example: POST /api/v1/templates/11714265276872/preview?draft=true
$post = [
'substitution_data' => $substitutionVariables,
];

$response = $this->prepareHttpClient(sprintf('/templates/%s/preview', urlencode($templateId)), $post)
->send()
;

return $this->parseResponse($response)['results'] ?? [];
}
}

0 comments on commit e87a884

Please sign in to comment.