summaryrefslogtreecommitdiffstats
path: root/examples/unwrapped/create_template.php
blob: ee4ff6c07043f15a94c9f20f545d400ff51500a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
namespace Examples\Unwrapped;
require_once (dirname(__FILE__).'/../bootstrap.php');
use SparkPost\SparkPost;
use SparkPost\APIResource;
use GuzzleHttp\Client;
use Ivory\HttpAdapter\Guzzle6HttpAdapter;

$key = 'YOUR API KEY';
$httpAdapter = new Guzzle6HttpAdapter(new Client());
SparkPost::configure($httpAdapter, ['key'=>$key]);

try {
	// define the endpoint
	APIResource::$endpoint = 'templates';

	$templateConfig = [
		'name' => 'Summer Sale!',
    'id'=>'summer-sale',
		'content'=> [
      'from' => 'john.doe@sparkpostbox.com',
		  'subject' => 'Summer deals',
		  'html' => '<b>Check out these deals!</b>'
    ]
	];
	$results = APIResource::create($templateConfig);
  var_dump($results);
	echo 'Congrats you can use your SDK!';
} catch (\Exception $exception) {
	echo $exception->getMessage();
}
?>