|
10 | 10 | $headers = ['Authorization: Bearer ' . $apiKey];
|
11 | 11 | $client = new SendGrid\Client('https://api.sendgrid.com', $headers, '/v3');
|
12 | 12 |
|
13 |
| -// GET Collection |
14 |
| -$query_params = ['limit' => 100, 'offset' => 0]; |
15 |
| -$request_headers = ['X-Mock: 200']; |
16 |
| -$response = $client->api_keys()->get(null, $query_params, $request_headers); |
| 13 | +// GET /v3/api_keys - retrieve all API Keys that belong to the user |
| 14 | +$queryParams = ['limit' => 100, 'offset' => 0]; |
| 15 | +$requestHeaders = ['X-Mock: 200']; |
| 16 | +$response = $client->api_keys()->get(null, $queryParams, $requestHeaders); |
17 | 17 | echo $response->statusCode();
|
18 | 18 | echo $response->body();
|
19 | 19 | echo $response->headers();
|
20 | 20 |
|
21 |
| -// GET with auto retry on rate limit |
22 |
| -$query_params = ['limit' => 100, 'offset' => 0]; |
23 |
| -$request_headers = ['X-Mock: 200']; |
24 |
| -$retryOnLimit = true; |
25 |
| -$response = $client->api_keys()->get(null, $query_params, $request_headers, $retryOnLimit); |
26 |
| -echo $response->statusCode(); |
27 |
| -echo $response->body(); |
28 |
| -echo $response->headers(); |
| 21 | +// GET /v3/api_keys - retrieve all API Keys that belong to the user |
| 22 | +$queryParams = ['limit' => 100, 'offset' => 0]; |
| 23 | +$requestHeaders = ['X-Mock: 200']; |
| 24 | +$retryOnLimit = true; // with auto retry on rate limit |
| 25 | +$response = $client->api_keys()->get(null, $queryParams, $requestHeaders, $retryOnLimit); |
29 | 26 |
|
30 |
| -// POST |
31 |
| -$request_body = [ |
| 27 | +// POST /v3/api_keys - create a new user API Key |
| 28 | +$requestBody = [ |
32 | 29 | 'name' => 'My PHP API Key',
|
33 | 30 | 'scopes' => [
|
34 | 31 | 'mail.send',
|
35 | 32 | 'alerts.create',
|
36 | 33 | 'alerts.read'
|
37 | 34 | ]
|
38 | 35 | ];
|
39 |
| -$response = $client->api_keys()->post($request_body); |
40 |
| -echo $response->statusCode(); |
41 |
| -echo $response->body(); |
42 |
| -echo $response->headers(); |
43 |
| -$response_body = json_decode($response->body()); |
44 |
| -$api_key_id = $response_body->api_key_id; |
| 36 | +$response = $client->api_keys()->post($requestBody); |
| 37 | +$responseBody = json_decode($response->body(), true); |
| 38 | +$apiKeyId = $responseBody['api_key_id']; |
45 | 39 |
|
46 |
| -// GET Single |
47 |
| -$response = $client->version('/v3')->api_keys()->_($api_key_id)->get(); |
48 |
| -echo $response->statusCode(); |
49 |
| -echo $response->body(); |
50 |
| -echo $response->headers(); |
| 40 | +// GET /v3/api_keys/{api_key_id} - retrieve a single API Key |
| 41 | +$response = $client->api_keys()->_($apiKeyId)->get(); |
51 | 42 |
|
52 |
| -// PATCH |
53 |
| -$request_body = [ |
| 43 | +// PATCH /v3/api_keys/{api_key_id} - update the name of an existing API Key |
| 44 | +$requestBody = [ |
54 | 45 | 'name' => 'A New Hope'
|
55 | 46 | ];
|
56 |
| -$response = $client->api_keys()->_($api_key_id)->patch($request_body); |
57 |
| -echo $response->statusCode(); |
58 |
| -echo $response->body(); |
59 |
| -echo $response->headers(); |
| 47 | +$response = $client->api_keys()->_($apiKeyId)->patch($requestBody); |
60 | 48 |
|
61 |
| -// PUT |
62 |
| -$request_body = [ |
| 49 | +// PUT /v3/api_keys/{api_key_id} - update the name and scopes of a given API Key |
| 50 | +$requestBody = [ |
63 | 51 | 'name' => 'A New Hope',
|
64 | 52 | 'scopes' => [
|
65 | 53 | 'user.profile.read',
|
66 | 54 | 'user.profile.update'
|
67 | 55 | ]
|
68 | 56 | ];
|
69 |
| -$response = $client->api_keys()->_($api_key_id)->put($request_body); |
70 |
| -echo $response->statusCode(); |
71 |
| -echo $response->body(); |
72 |
| -echo $response->headers(); |
| 57 | +$response = $client->api_keys()->_($apiKeyId)->put($requestBody); |
73 | 58 |
|
74 |
| -// DELETE |
75 |
| -$response = $client->api_keys()->_($api_key_id)->delete(); |
76 |
| -echo $response->statusCode(); |
77 |
| -echo $response->body(); |
78 |
| -echo $response->headers(); |
| 59 | +// DELETE /v3/api_keys/{api_key_id} - revoke an existing API Key |
| 60 | +$response = $client->api_keys()->_($apiKeyId)->delete(); |
0 commit comments