103 |
- |
1 |
<?php
|
|
|
2 |
// If you are using Composer
|
|
|
3 |
require 'vendor/autoload.php';
|
|
|
4 |
|
|
|
5 |
|
|
|
6 |
$apiKey = getenv('SENDGRID_API_KEY');
|
|
|
7 |
$sg = new \SendGrid($apiKey);
|
|
|
8 |
|
|
|
9 |
////////////////////////////////////////////////////
|
|
|
10 |
// Create a transactional template. #
|
|
|
11 |
// POST /templates #
|
|
|
12 |
|
|
|
13 |
$request_body = json_decode('{
|
|
|
14 |
"name": "example_name"
|
|
|
15 |
}');
|
|
|
16 |
$response = $sg->client->templates()->post($request_body);
|
|
|
17 |
echo $response->statusCode();
|
|
|
18 |
echo $response->body();
|
|
|
19 |
echo $response->headers();
|
|
|
20 |
|
|
|
21 |
////////////////////////////////////////////////////
|
|
|
22 |
// Retrieve all transactional templates. #
|
|
|
23 |
// GET /templates #
|
|
|
24 |
|
|
|
25 |
$response = $sg->client->templates()->get();
|
|
|
26 |
echo $response->statusCode();
|
|
|
27 |
echo $response->body();
|
|
|
28 |
echo $response->headers();
|
|
|
29 |
|
|
|
30 |
////////////////////////////////////////////////////
|
|
|
31 |
// Edit a transactional template. #
|
|
|
32 |
// PATCH /templates/{template_id} #
|
|
|
33 |
|
|
|
34 |
$request_body = json_decode('{
|
|
|
35 |
"name": "new_example_name"
|
|
|
36 |
}');
|
|
|
37 |
$template_id = "test_url_param";
|
|
|
38 |
$response = $sg->client->templates()->_($template_id)->patch($request_body);
|
|
|
39 |
echo $response->statusCode();
|
|
|
40 |
echo $response->body();
|
|
|
41 |
echo $response->headers();
|
|
|
42 |
|
|
|
43 |
////////////////////////////////////////////////////
|
|
|
44 |
// Retrieve a single transactional template. #
|
|
|
45 |
// GET /templates/{template_id} #
|
|
|
46 |
|
|
|
47 |
$template_id = "test_url_param";
|
|
|
48 |
$response = $sg->client->templates()->_($template_id)->get();
|
|
|
49 |
echo $response->statusCode();
|
|
|
50 |
echo $response->body();
|
|
|
51 |
echo $response->headers();
|
|
|
52 |
|
|
|
53 |
////////////////////////////////////////////////////
|
|
|
54 |
// Delete a template. #
|
|
|
55 |
// DELETE /templates/{template_id} #
|
|
|
56 |
|
|
|
57 |
$template_id = "test_url_param";
|
|
|
58 |
$response = $sg->client->templates()->_($template_id)->delete();
|
|
|
59 |
echo $response->statusCode();
|
|
|
60 |
echo $response->body();
|
|
|
61 |
echo $response->headers();
|
|
|
62 |
|
|
|
63 |
////////////////////////////////////////////////////
|
|
|
64 |
// Create a new transactional template version. #
|
|
|
65 |
// POST /templates/{template_id}/versions #
|
|
|
66 |
|
|
|
67 |
$request_body = json_decode('{
|
|
|
68 |
"active": 1,
|
|
|
69 |
"html_content": "<%body%>",
|
|
|
70 |
"name": "example_version_name",
|
|
|
71 |
"plain_content": "<%body%>",
|
|
|
72 |
"subject": "<%subject%>",
|
|
|
73 |
"template_id": "ddb96bbc-9b92-425e-8979-99464621b543"
|
|
|
74 |
}');
|
|
|
75 |
$template_id = "test_url_param";
|
|
|
76 |
$response = $sg->client->templates()->_($template_id)->versions()->post($request_body);
|
|
|
77 |
echo $response->statusCode();
|
|
|
78 |
echo $response->body();
|
|
|
79 |
echo $response->headers();
|
|
|
80 |
|
|
|
81 |
////////////////////////////////////////////////////
|
|
|
82 |
// Edit a transactional template version. #
|
|
|
83 |
// PATCH /templates/{template_id}/versions/{version_id} #
|
|
|
84 |
|
|
|
85 |
$request_body = json_decode('{
|
|
|
86 |
"active": 1,
|
|
|
87 |
"html_content": "<%body%>",
|
|
|
88 |
"name": "updated_example_name",
|
|
|
89 |
"plain_content": "<%body%>",
|
|
|
90 |
"subject": "<%subject%>"
|
|
|
91 |
}');
|
|
|
92 |
$template_id = "test_url_param";
|
|
|
93 |
$version_id = "test_url_param";
|
|
|
94 |
$response = $sg->client->templates()->_($template_id)->versions()->_($version_id)->patch($request_body);
|
|
|
95 |
echo $response->statusCode();
|
|
|
96 |
echo $response->body();
|
|
|
97 |
echo $response->headers();
|
|
|
98 |
|
|
|
99 |
////////////////////////////////////////////////////
|
|
|
100 |
// Retrieve a specific transactional template version. #
|
|
|
101 |
// GET /templates/{template_id}/versions/{version_id} #
|
|
|
102 |
|
|
|
103 |
$template_id = "test_url_param";
|
|
|
104 |
$version_id = "test_url_param";
|
|
|
105 |
$response = $sg->client->templates()->_($template_id)->versions()->_($version_id)->get();
|
|
|
106 |
echo $response->statusCode();
|
|
|
107 |
echo $response->body();
|
|
|
108 |
echo $response->headers();
|
|
|
109 |
|
|
|
110 |
////////////////////////////////////////////////////
|
|
|
111 |
// Delete a transactional template version. #
|
|
|
112 |
// DELETE /templates/{template_id}/versions/{version_id} #
|
|
|
113 |
|
|
|
114 |
$template_id = "test_url_param";
|
|
|
115 |
$version_id = "test_url_param";
|
|
|
116 |
$response = $sg->client->templates()->_($template_id)->versions()->_($version_id)->delete();
|
|
|
117 |
echo $response->statusCode();
|
|
|
118 |
echo $response->body();
|
|
|
119 |
echo $response->headers();
|
|
|
120 |
|
|
|
121 |
////////////////////////////////////////////////////
|
|
|
122 |
// Activate a transactional template version. #
|
|
|
123 |
// POST /templates/{template_id}/versions/{version_id}/activate #
|
|
|
124 |
|
|
|
125 |
$template_id = "test_url_param";
|
|
|
126 |
$version_id = "test_url_param";
|
|
|
127 |
$response = $sg->client->templates()->_($template_id)->versions()->_($version_id)->activate()->post();
|
|
|
128 |
echo $response->statusCode();
|
|
|
129 |
echo $response->body();
|
|
|
130 |
echo $response->headers();
|