| 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 |
// Get a user's account information. #
|
|
|
11 |
// GET /user/account #
|
|
|
12 |
|
|
|
13 |
$response = $sg->client->user()->account()->get();
|
|
|
14 |
echo $response->statusCode();
|
|
|
15 |
echo $response->body();
|
|
|
16 |
echo $response->headers();
|
|
|
17 |
|
|
|
18 |
////////////////////////////////////////////////////
|
|
|
19 |
// Retrieve your credit balance #
|
|
|
20 |
// GET /user/credits #
|
|
|
21 |
|
|
|
22 |
$response = $sg->client->user()->credits()->get();
|
|
|
23 |
echo $response->statusCode();
|
|
|
24 |
echo $response->body();
|
|
|
25 |
echo $response->headers();
|
|
|
26 |
|
|
|
27 |
////////////////////////////////////////////////////
|
|
|
28 |
// Update your account email address #
|
|
|
29 |
// PUT /user/email #
|
|
|
30 |
|
|
|
31 |
$request_body = json_decode('{
|
|
|
32 |
"email": "example@example.com"
|
|
|
33 |
}');
|
|
|
34 |
$response = $sg->client->user()->email()->put($request_body);
|
|
|
35 |
echo $response->statusCode();
|
|
|
36 |
echo $response->body();
|
|
|
37 |
echo $response->headers();
|
|
|
38 |
|
|
|
39 |
////////////////////////////////////////////////////
|
|
|
40 |
// Retrieve your account email address #
|
|
|
41 |
// GET /user/email #
|
|
|
42 |
|
|
|
43 |
$response = $sg->client->user()->email()->get();
|
|
|
44 |
echo $response->statusCode();
|
|
|
45 |
echo $response->body();
|
|
|
46 |
echo $response->headers();
|
|
|
47 |
|
|
|
48 |
////////////////////////////////////////////////////
|
|
|
49 |
// Update your password #
|
|
|
50 |
// PUT /user/password #
|
|
|
51 |
|
|
|
52 |
$request_body = json_decode('{
|
|
|
53 |
"new_password": "new_password",
|
|
|
54 |
"old_password": "old_password"
|
|
|
55 |
}');
|
|
|
56 |
$response = $sg->client->user()->password()->put($request_body);
|
|
|
57 |
echo $response->statusCode();
|
|
|
58 |
echo $response->body();
|
|
|
59 |
echo $response->headers();
|
|
|
60 |
|
|
|
61 |
////////////////////////////////////////////////////
|
|
|
62 |
// Update a user's profile #
|
|
|
63 |
// PATCH /user/profile #
|
|
|
64 |
|
|
|
65 |
$request_body = json_decode('{
|
|
|
66 |
"city": "Orange",
|
|
|
67 |
"first_name": "Example",
|
|
|
68 |
"last_name": "User"
|
|
|
69 |
}');
|
|
|
70 |
$response = $sg->client->user()->profile()->patch($request_body);
|
|
|
71 |
echo $response->statusCode();
|
|
|
72 |
echo $response->body();
|
|
|
73 |
echo $response->headers();
|
|
|
74 |
|
|
|
75 |
////////////////////////////////////////////////////
|
|
|
76 |
// Get a user's profile #
|
|
|
77 |
// GET /user/profile #
|
|
|
78 |
|
|
|
79 |
$response = $sg->client->user()->profile()->get();
|
|
|
80 |
echo $response->statusCode();
|
|
|
81 |
echo $response->body();
|
|
|
82 |
echo $response->headers();
|
|
|
83 |
|
|
|
84 |
////////////////////////////////////////////////////
|
|
|
85 |
// Cancel or pause a scheduled send #
|
|
|
86 |
// POST /user/scheduled_sends #
|
|
|
87 |
|
|
|
88 |
$request_body = json_decode('{
|
|
|
89 |
"batch_id": "YOUR_BATCH_ID",
|
|
|
90 |
"status": "pause"
|
|
|
91 |
}');
|
|
|
92 |
$response = $sg->client->user()->scheduled_sends()->post($request_body);
|
|
|
93 |
echo $response->statusCode();
|
|
|
94 |
echo $response->body();
|
|
|
95 |
echo $response->headers();
|
|
|
96 |
|
|
|
97 |
////////////////////////////////////////////////////
|
|
|
98 |
// Retrieve all scheduled sends #
|
|
|
99 |
// GET /user/scheduled_sends #
|
|
|
100 |
|
|
|
101 |
$response = $sg->client->user()->scheduled_sends()->get();
|
|
|
102 |
echo $response->statusCode();
|
|
|
103 |
echo $response->body();
|
|
|
104 |
echo $response->headers();
|
|
|
105 |
|
|
|
106 |
////////////////////////////////////////////////////
|
|
|
107 |
// Update user scheduled send information #
|
|
|
108 |
// PATCH /user/scheduled_sends/{batch_id} #
|
|
|
109 |
|
|
|
110 |
$request_body = json_decode('{
|
|
|
111 |
"status": "pause"
|
|
|
112 |
}');
|
|
|
113 |
$batch_id = "test_url_param";
|
|
|
114 |
$response = $sg->client->user()->scheduled_sends()->_($batch_id)->patch($request_body);
|
|
|
115 |
echo $response->statusCode();
|
|
|
116 |
echo $response->body();
|
|
|
117 |
echo $response->headers();
|
|
|
118 |
|
|
|
119 |
////////////////////////////////////////////////////
|
|
|
120 |
// Retrieve scheduled send #
|
|
|
121 |
// GET /user/scheduled_sends/{batch_id} #
|
|
|
122 |
|
|
|
123 |
$batch_id = "test_url_param";
|
|
|
124 |
$response = $sg->client->user()->scheduled_sends()->_($batch_id)->get();
|
|
|
125 |
echo $response->statusCode();
|
|
|
126 |
echo $response->body();
|
|
|
127 |
echo $response->headers();
|
|
|
128 |
|
|
|
129 |
////////////////////////////////////////////////////
|
|
|
130 |
// Delete a cancellation or pause of a scheduled send #
|
|
|
131 |
// DELETE /user/scheduled_sends/{batch_id} #
|
|
|
132 |
|
|
|
133 |
$batch_id = "test_url_param";
|
|
|
134 |
$response = $sg->client->user()->scheduled_sends()->_($batch_id)->delete();
|
|
|
135 |
echo $response->statusCode();
|
|
|
136 |
echo $response->body();
|
|
|
137 |
echo $response->headers();
|
|
|
138 |
|
|
|
139 |
////////////////////////////////////////////////////
|
|
|
140 |
// Update Enforced TLS settings #
|
|
|
141 |
// PATCH /user/settings/enforced_tls #
|
|
|
142 |
|
|
|
143 |
$request_body = json_decode('{
|
|
|
144 |
"require_tls": true,
|
|
|
145 |
"require_valid_cert": false
|
|
|
146 |
}');
|
|
|
147 |
$response = $sg->client->user()->settings()->enforced_tls()->patch($request_body);
|
|
|
148 |
echo $response->statusCode();
|
|
|
149 |
echo $response->body();
|
|
|
150 |
echo $response->headers();
|
|
|
151 |
|
|
|
152 |
////////////////////////////////////////////////////
|
|
|
153 |
// Retrieve current Enforced TLS settings. #
|
|
|
154 |
// GET /user/settings/enforced_tls #
|
|
|
155 |
|
|
|
156 |
$response = $sg->client->user()->settings()->enforced_tls()->get();
|
|
|
157 |
echo $response->statusCode();
|
|
|
158 |
echo $response->body();
|
|
|
159 |
echo $response->headers();
|
|
|
160 |
|
|
|
161 |
////////////////////////////////////////////////////
|
|
|
162 |
// Update your username #
|
|
|
163 |
// PUT /user/username #
|
|
|
164 |
|
|
|
165 |
$request_body = json_decode('{
|
|
|
166 |
"username": "test_username"
|
|
|
167 |
}');
|
|
|
168 |
$response = $sg->client->user()->username()->put($request_body);
|
|
|
169 |
echo $response->statusCode();
|
|
|
170 |
echo $response->body();
|
|
|
171 |
echo $response->headers();
|
|
|
172 |
|
|
|
173 |
////////////////////////////////////////////////////
|
|
|
174 |
// Retrieve your username #
|
|
|
175 |
// GET /user/username #
|
|
|
176 |
|
|
|
177 |
$response = $sg->client->user()->username()->get();
|
|
|
178 |
echo $response->statusCode();
|
|
|
179 |
echo $response->body();
|
|
|
180 |
echo $response->headers();
|
|
|
181 |
|
|
|
182 |
////////////////////////////////////////////////////
|
|
|
183 |
// Update Event Notification Settings #
|
|
|
184 |
// PATCH /user/webhooks/event/settings #
|
|
|
185 |
|
|
|
186 |
$request_body = json_decode('{
|
|
|
187 |
"bounce": true,
|
|
|
188 |
"click": true,
|
|
|
189 |
"deferred": true,
|
|
|
190 |
"delivered": true,
|
|
|
191 |
"dropped": true,
|
|
|
192 |
"enabled": true,
|
|
|
193 |
"group_resubscribe": true,
|
|
|
194 |
"group_unsubscribe": true,
|
|
|
195 |
"open": true,
|
|
|
196 |
"processed": true,
|
|
|
197 |
"spam_report": true,
|
|
|
198 |
"unsubscribe": true,
|
|
|
199 |
"url": "url"
|
|
|
200 |
}');
|
|
|
201 |
$response = $sg->client->user()->webhooks()->event()->settings()->patch($request_body);
|
|
|
202 |
echo $response->statusCode();
|
|
|
203 |
echo $response->body();
|
|
|
204 |
echo $response->headers();
|
|
|
205 |
|
|
|
206 |
////////////////////////////////////////////////////
|
|
|
207 |
// Retrieve Event Webhook settings #
|
|
|
208 |
// GET /user/webhooks/event/settings #
|
|
|
209 |
|
|
|
210 |
$response = $sg->client->user()->webhooks()->event()->settings()->get();
|
|
|
211 |
echo $response->statusCode();
|
|
|
212 |
echo $response->body();
|
|
|
213 |
echo $response->headers();
|
|
|
214 |
|
|
|
215 |
////////////////////////////////////////////////////
|
|
|
216 |
// Test Event Notification Settings #
|
|
|
217 |
// POST /user/webhooks/event/test #
|
|
|
218 |
|
|
|
219 |
$request_body = json_decode('{
|
|
|
220 |
"url": "url"
|
|
|
221 |
}');
|
|
|
222 |
$response = $sg->client->user()->webhooks()->event()->test()->post($request_body);
|
|
|
223 |
echo $response->statusCode();
|
|
|
224 |
echo $response->body();
|
|
|
225 |
echo $response->headers();
|
|
|
226 |
|
|
|
227 |
////////////////////////////////////////////////////
|
|
|
228 |
// Create a parse setting #
|
|
|
229 |
// POST /user/webhooks/parse/settings #
|
|
|
230 |
|
|
|
231 |
$request_body = json_decode('{
|
|
|
232 |
"hostname": "myhostname.com",
|
|
|
233 |
"send_raw": false,
|
|
|
234 |
"spam_check": true,
|
|
|
235 |
"url": "http://email.myhosthame.com"
|
|
|
236 |
}');
|
|
|
237 |
$response = $sg->client->user()->webhooks()->parse()->settings()->post($request_body);
|
|
|
238 |
echo $response->statusCode();
|
|
|
239 |
echo $response->body();
|
|
|
240 |
echo $response->headers();
|
|
|
241 |
|
|
|
242 |
////////////////////////////////////////////////////
|
|
|
243 |
// Retrieve all parse settings #
|
|
|
244 |
// GET /user/webhooks/parse/settings #
|
|
|
245 |
|
|
|
246 |
$response = $sg->client->user()->webhooks()->parse()->settings()->get();
|
|
|
247 |
echo $response->statusCode();
|
|
|
248 |
echo $response->body();
|
|
|
249 |
echo $response->headers();
|
|
|
250 |
|
|
|
251 |
////////////////////////////////////////////////////
|
|
|
252 |
// Update a parse setting #
|
|
|
253 |
// PATCH /user/webhooks/parse/settings/{hostname} #
|
|
|
254 |
|
|
|
255 |
$request_body = json_decode('{
|
|
|
256 |
"send_raw": true,
|
|
|
257 |
"spam_check": false,
|
|
|
258 |
"url": "http://newdomain.com/parse"
|
|
|
259 |
}');
|
|
|
260 |
$hostname = "test_url_param";
|
|
|
261 |
$response = $sg->client->user()->webhooks()->parse()->settings()->_($hostname)->patch($request_body);
|
|
|
262 |
echo $response->statusCode();
|
|
|
263 |
echo $response->body();
|
|
|
264 |
echo $response->headers();
|
|
|
265 |
|
|
|
266 |
////////////////////////////////////////////////////
|
|
|
267 |
// Retrieve a specific parse setting #
|
|
|
268 |
// GET /user/webhooks/parse/settings/{hostname} #
|
|
|
269 |
|
|
|
270 |
$hostname = "test_url_param";
|
|
|
271 |
$response = $sg->client->user()->webhooks()->parse()->settings()->_($hostname)->get();
|
|
|
272 |
echo $response->statusCode();
|
|
|
273 |
echo $response->body();
|
|
|
274 |
echo $response->headers();
|
|
|
275 |
|
|
|
276 |
////////////////////////////////////////////////////
|
|
|
277 |
// Delete a parse setting #
|
|
|
278 |
// DELETE /user/webhooks/parse/settings/{hostname} #
|
|
|
279 |
|
|
|
280 |
$hostname = "test_url_param";
|
|
|
281 |
$response = $sg->client->user()->webhooks()->parse()->settings()->_($hostname)->delete();
|
|
|
282 |
echo $response->statusCode();
|
|
|
283 |
echo $response->body();
|
|
|
284 |
echo $response->headers();
|
|
|
285 |
|
|
|
286 |
////////////////////////////////////////////////////
|
|
|
287 |
// Retrieves Inbound Parse Webhook statistics. #
|
|
|
288 |
// GET /user/webhooks/parse/stats #
|
|
|
289 |
|
|
|
290 |
$query_params = json_decode('{"aggregated_by": "day", "limit": "test_string", "start_date": "2016-01-01", "end_date": "2016-04-01", "offset": "test_string"}');
|
|
|
291 |
$response = $sg->client->user()->webhooks()->parse()->stats()->get(null, $query_params);
|
|
|
292 |
echo $response->statusCode();
|
|
|
293 |
echo $response->body();
|
|
|
294 |
echo $response->headers();
|