blob: eff23ec602eb4793afd79d4fe0f4333bf2efbd01 (
plain)
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
86
87
88
89
|
using System;
using SendGrid.Helpers.Mail;
using System.Collections.Generic;
string _apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY", EnvironmentVariableTarget.User);
dynamic sg = new SendGrid.SendGridAPIClient(_apiKey);
////////////////////////////////////////////////////////
// Create API keys
// POST /api_keys
string data = @"{
'name': 'My API Key',
'scopes': [
'mail.send',
'alerts.create',
'alerts.read'
]
}";
dynamic response = sg.client.api_keys.post(requestBody: data);
Console.WriteLine(response.StatusCode);
Console.WriteLine(response.Body.ReadAsStringAsync().Result);
Console.WriteLine(response.Headers.ToString());
Console.ReadLine();
////////////////////////////////////////////////////////
// Retrieve all API Keys belonging to the authenticated user
// GET /api_keys
dynamic response = sg.client.api_keys.get();
Console.WriteLine(response.StatusCode);
Console.WriteLine(response.Body.ReadAsStringAsync().Result);
Console.WriteLine(response.Headers.ToString());
Console.ReadLine();
////////////////////////////////////////////////////////
// Update the name & scopes of an API Key
// PUT /api_keys/{api_key_id}
string data = @"{
'name': 'A New Hope',
'scopes': [
'user.profile.read',
'user.profile.update'
]
}";
var api_key_id = "test_url_param";
dynamic response = sg.client.api_keys._(api_key_id).put(requestBody: data);
Console.WriteLine(response.StatusCode);
Console.WriteLine(response.Body.ReadAsStringAsync().Result);
Console.WriteLine(response.Headers.ToString());
Console.ReadLine();
////////////////////////////////////////////////////////
// Update API keys
// PATCH /api_keys/{api_key_id}
string data = @"{
'name': 'A New Hope'
}";
var api_key_id = "test_url_param";
dynamic response = sg.client.api_keys._(api_key_id).patch(requestBody: data);
Console.WriteLine(response.StatusCode);
Console.WriteLine(response.Body.ReadAsStringAsync().Result);
Console.WriteLine(response.Headers.ToString());
Console.ReadLine();
////////////////////////////////////////////////////////
// Retrieve an existing API Key
// GET /api_keys/{api_key_id}
var api_key_id = "test_url_param";
dynamic response = sg.client.api_keys._(api_key_id).get();
Console.WriteLine(response.StatusCode);
Console.WriteLine(response.Body.ReadAsStringAsync().Result);
Console.WriteLine(response.Headers.ToString());
Console.ReadLine();
////////////////////////////////////////////////////////
// Delete API keys
// DELETE /api_keys/{api_key_id}
var api_key_id = "test_url_param";
dynamic response = sg.client.api_keys._(api_key_id).delete();
Console.WriteLine(response.StatusCode);
Console.WriteLine(response.Body.ReadAsStringAsync().Result);
Console.WriteLine(response.Headers.ToString());
Console.ReadLine();
|