/var/www/hkosl.com/demo_google/application/vendor/sendgrid/sendgrid/examples/apikeys/apikeys.php


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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
// If you are using Composer
require 'vendor/autoload.php';


$apiKey getenv('SENDGRID_API_KEY');
$sg = new \SendGrid($apiKey);

////////////////////////////////////////////////////
// Create API keys #
// POST /api_keys #

$request_body json_decode('{
  "name": "My API Key", 
  "sample": "data", 
  "scopes": [
    "mail.send", 
    "alerts.create", 
    "alerts.read"
  ]
}'
);
$response $sg->client->api_keys()->post($request_body);
echo 
$response->statusCode();
echo 
$response->body();
print_r($response->headers());

////////////////////////////////////////////////////
// Retrieve all API Keys belonging to the authenticated user #
// GET /api_keys #

$query_params json_decode('{"limit": 1}');
$response $sg->client->api_keys()->get(null$query_params);
echo 
$response->statusCode();
echo 
$response->body();
print_r($response->headers());

////////////////////////////////////////////////////
// Update the name & scopes of an API Key #
// PUT /api_keys/{api_key_id} #

$request_body json_decode('{
  "name": "A New Hope", 
  "scopes": [
    "user.profile.read", 
    "user.profile.update"
  ]
}'
);
$api_key_id "test_url_param";
$response $sg->client->api_keys()->_($api_key_id)->put($request_body);
echo 
$response->statusCode();
echo 
$response->body();
print_r($response->headers());

////////////////////////////////////////////////////
// Update API keys #
// PATCH /api_keys/{api_key_id} #

$request_body json_decode('{
  "name": "A New Hope"
}'
);
$api_key_id "test_url_param";
$response $sg->client->api_keys()->_($api_key_id)->patch($request_body);
echo 
$response->statusCode();
echo 
$response->body();
print_r($response->headers());

////////////////////////////////////////////////////
// Retrieve an existing API Key #
// GET /api_keys/{api_key_id} #

$api_key_id "test_url_param";
$response $sg->client->api_keys()->_($api_key_id)->get();
echo 
$response->statusCode();
echo 
$response->body();
print_r($response->headers());

////////////////////////////////////////////////////
// Delete API keys #
// DELETE /api_keys/{api_key_id} #

$api_key_id "test_url_param";
$response $sg->client->api_keys()->_($api_key_id)->delete();
echo 
$response->statusCode();
echo 
$response->body();
print_r($response->headers());