| 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 new suppression group #
|
|
|
11 |
// POST /asm/groups #
|
|
|
12 |
|
|
|
13 |
$request_body = json_decode('{
|
|
|
14 |
"description": "Suggestions for products our users might like.",
|
|
|
15 |
"is_default": true,
|
|
|
16 |
"name": "Product Suggestions"
|
|
|
17 |
}');
|
|
|
18 |
$response = $sg->client->asm()->groups()->post($request_body);
|
|
|
19 |
echo $response->statusCode();
|
|
|
20 |
echo $response->body();
|
|
|
21 |
echo $response->headers();
|
|
|
22 |
|
|
|
23 |
////////////////////////////////////////////////////
|
|
|
24 |
// Retrieve information about multiple suppression groups #
|
|
|
25 |
// GET /asm/groups #
|
|
|
26 |
|
|
|
27 |
$query_params = json_decode('{"id": 1}');
|
|
|
28 |
$response = $sg->client->asm()->groups()->get(null, $query_params);
|
|
|
29 |
echo $response->statusCode();
|
|
|
30 |
echo $response->body();
|
|
|
31 |
echo $response->headers();
|
|
|
32 |
|
|
|
33 |
////////////////////////////////////////////////////
|
|
|
34 |
// Update a suppression group. #
|
|
|
35 |
// PATCH /asm/groups/{group_id} #
|
|
|
36 |
|
|
|
37 |
$request_body = json_decode('{
|
|
|
38 |
"description": "Suggestions for items our users might like.",
|
|
|
39 |
"id": 103,
|
|
|
40 |
"name": "Item Suggestions"
|
|
|
41 |
}');
|
|
|
42 |
$group_id = "test_url_param";
|
|
|
43 |
$response = $sg->client->asm()->groups()->_($group_id)->patch($request_body);
|
|
|
44 |
echo $response->statusCode();
|
|
|
45 |
echo $response->body();
|
|
|
46 |
echo $response->headers();
|
|
|
47 |
|
|
|
48 |
////////////////////////////////////////////////////
|
|
|
49 |
// Get information on a single suppression group. #
|
|
|
50 |
// GET /asm/groups/{group_id} #
|
|
|
51 |
|
|
|
52 |
$group_id = "test_url_param";
|
|
|
53 |
$response = $sg->client->asm()->groups()->_($group_id)->get();
|
|
|
54 |
echo $response->statusCode();
|
|
|
55 |
echo $response->body();
|
|
|
56 |
echo $response->headers();
|
|
|
57 |
|
|
|
58 |
////////////////////////////////////////////////////
|
|
|
59 |
// Delete a suppression group. #
|
|
|
60 |
// DELETE /asm/groups/{group_id} #
|
|
|
61 |
|
|
|
62 |
$group_id = "test_url_param";
|
|
|
63 |
$response = $sg->client->asm()->groups()->_($group_id)->delete();
|
|
|
64 |
echo $response->statusCode();
|
|
|
65 |
echo $response->body();
|
|
|
66 |
echo $response->headers();
|
|
|
67 |
|
|
|
68 |
////////////////////////////////////////////////////
|
|
|
69 |
// Add suppressions to a suppression group #
|
|
|
70 |
// POST /asm/groups/{group_id}/suppressions #
|
|
|
71 |
|
|
|
72 |
$request_body = json_decode('{
|
|
|
73 |
"recipient_emails": [
|
|
|
74 |
"test1@example.com",
|
|
|
75 |
"test2@example.com"
|
|
|
76 |
]
|
|
|
77 |
}');
|
|
|
78 |
$group_id = "test_url_param";
|
|
|
79 |
$response = $sg->client->asm()->groups()->_($group_id)->suppressions()->post($request_body);
|
|
|
80 |
echo $response->statusCode();
|
|
|
81 |
echo $response->body();
|
|
|
82 |
echo $response->headers();
|
|
|
83 |
|
|
|
84 |
////////////////////////////////////////////////////
|
|
|
85 |
// Retrieve all suppressions for a suppression group #
|
|
|
86 |
// GET /asm/groups/{group_id}/suppressions #
|
|
|
87 |
|
|
|
88 |
$group_id = "test_url_param";
|
|
|
89 |
$response = $sg->client->asm()->groups()->_($group_id)->suppressions()->get();
|
|
|
90 |
echo $response->statusCode();
|
|
|
91 |
echo $response->body();
|
|
|
92 |
echo $response->headers();
|
|
|
93 |
|
|
|
94 |
////////////////////////////////////////////////////
|
|
|
95 |
// Search for suppressions within a group #
|
|
|
96 |
// POST /asm/groups/{group_id}/suppressions/search #
|
|
|
97 |
|
|
|
98 |
$request_body = json_decode('{
|
|
|
99 |
"recipient_emails": [
|
|
|
100 |
"exists1@example.com",
|
|
|
101 |
"exists2@example.com",
|
|
|
102 |
"doesnotexists@example.com"
|
|
|
103 |
]
|
|
|
104 |
}');
|
|
|
105 |
$group_id = "test_url_param";
|
|
|
106 |
$response = $sg->client->asm()->groups()->_($group_id)->suppressions()->search()->post($request_body);
|
|
|
107 |
echo $response->statusCode();
|
|
|
108 |
echo $response->body();
|
|
|
109 |
echo $response->headers();
|
|
|
110 |
|
|
|
111 |
////////////////////////////////////////////////////
|
|
|
112 |
// Delete a suppression from a suppression group #
|
|
|
113 |
// DELETE /asm/groups/{group_id}/suppressions/{email} #
|
|
|
114 |
|
|
|
115 |
$group_id = "test_url_param";
|
|
|
116 |
$email = "test_url_param";
|
|
|
117 |
$response = $sg->client->asm()->groups()->_($group_id)->suppressions()->_($email)->delete();
|
|
|
118 |
echo $response->statusCode();
|
|
|
119 |
echo $response->body();
|
|
|
120 |
echo $response->headers();
|
|
|
121 |
|
|
|
122 |
////////////////////////////////////////////////////
|
|
|
123 |
// Retrieve all suppressions #
|
|
|
124 |
// GET /asm/suppressions #
|
|
|
125 |
|
|
|
126 |
$response = $sg->client->asm()->suppressions()->get();
|
|
|
127 |
echo $response->statusCode();
|
|
|
128 |
echo $response->body();
|
|
|
129 |
echo $response->headers();
|
|
|
130 |
|
|
|
131 |
////////////////////////////////////////////////////
|
|
|
132 |
// Add recipient addresses to the global suppression group. #
|
|
|
133 |
// POST /asm/suppressions/global #
|
|
|
134 |
|
|
|
135 |
$request_body = json_decode('{
|
|
|
136 |
"recipient_emails": [
|
|
|
137 |
"test1@example.com",
|
|
|
138 |
"test2@example.com"
|
|
|
139 |
]
|
|
|
140 |
}');
|
|
|
141 |
$response = $sg->client->asm()->suppressions()->global()->post($request_body);
|
|
|
142 |
echo $response->statusCode();
|
|
|
143 |
echo $response->body();
|
|
|
144 |
echo $response->headers();
|
|
|
145 |
|
|
|
146 |
////////////////////////////////////////////////////
|
|
|
147 |
// Retrieve a Global Suppression #
|
|
|
148 |
// GET /asm/suppressions/global/{email} #
|
|
|
149 |
|
|
|
150 |
$email = "test_url_param";
|
|
|
151 |
$response = $sg->client->asm()->suppressions()->global()->_($email)->get();
|
|
|
152 |
echo $response->statusCode();
|
|
|
153 |
echo $response->body();
|
|
|
154 |
echo $response->headers();
|
|
|
155 |
|
|
|
156 |
////////////////////////////////////////////////////
|
|
|
157 |
// Delete a Global Suppression #
|
|
|
158 |
// DELETE /asm/suppressions/global/{email} #
|
|
|
159 |
|
|
|
160 |
$email = "test_url_param";
|
|
|
161 |
$response = $sg->client->asm()->suppressions()->global()->_($email)->delete();
|
|
|
162 |
echo $response->statusCode();
|
|
|
163 |
echo $response->body();
|
|
|
164 |
echo $response->headers();
|
|
|
165 |
|
|
|
166 |
////////////////////////////////////////////////////
|
|
|
167 |
// Retrieve all suppression groups for an email address #
|
|
|
168 |
// GET /asm/suppressions/{email} #
|
|
|
169 |
|
|
|
170 |
$email = "test_url_param";
|
|
|
171 |
$response = $sg->client->asm()->suppressions()->_($email)->get();
|
|
|
172 |
echo $response->statusCode();
|
|
|
173 |
echo $response->body();
|
|
|
174 |
echo $response->headers();
|