summaryrefslogtreecommitdiffstats
path: root/examples/templates/templates.cs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/templates/templates.cs')
-rw-r--r--examples/templates/templates.cs140
1 files changed, 140 insertions, 0 deletions
diff --git a/examples/templates/templates.cs b/examples/templates/templates.cs
new file mode 100644
index 0000000..beea4d0
--- /dev/null
+++ b/examples/templates/templates.cs
@@ -0,0 +1,140 @@
+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 a transactional template.
+// POST /templates
+
+string data = @"{
+ 'name': 'example_name'
+}";
+dynamic response = sg.client.templates.post(requestBody: data);
+Console.WriteLine(response.StatusCode);
+Console.WriteLine(response.Body.ReadAsStringAsync().Result);
+Console.WriteLine(response.Headers.ToString());
+Console.ReadLine();
+
+////////////////////////////////////////////////////////
+// Retrieve all transactional templates.
+// GET /templates
+
+dynamic response = sg.client.templates.get();
+Console.WriteLine(response.StatusCode);
+Console.WriteLine(response.Body.ReadAsStringAsync().Result);
+Console.WriteLine(response.Headers.ToString());
+Console.ReadLine();
+
+////////////////////////////////////////////////////////
+// Edit a transactional template.
+// PATCH /templates/{template_id}
+
+string data = @"{
+ 'name': 'new_example_name'
+}";
+var template_id = "test_url_param";
+dynamic response = sg.client.templates._(template_id).patch(requestBody: data);
+Console.WriteLine(response.StatusCode);
+Console.WriteLine(response.Body.ReadAsStringAsync().Result);
+Console.WriteLine(response.Headers.ToString());
+Console.ReadLine();
+
+////////////////////////////////////////////////////////
+// Retrieve a single transactional template.
+// GET /templates/{template_id}
+
+var template_id = "test_url_param";
+dynamic response = sg.client.templates._(template_id).get();
+Console.WriteLine(response.StatusCode);
+Console.WriteLine(response.Body.ReadAsStringAsync().Result);
+Console.WriteLine(response.Headers.ToString());
+Console.ReadLine();
+
+////////////////////////////////////////////////////////
+// Delete a template.
+// DELETE /templates/{template_id}
+
+var template_id = "test_url_param";
+dynamic response = sg.client.templates._(template_id).delete();
+Console.WriteLine(response.StatusCode);
+Console.WriteLine(response.Body.ReadAsStringAsync().Result);
+Console.WriteLine(response.Headers.ToString());
+Console.ReadLine();
+
+////////////////////////////////////////////////////////
+// Create a new transactional template version.
+// POST /templates/{template_id}/versions
+
+string data = @"{
+ 'active': 1,
+ 'html_content': '<%body%>',
+ 'name': 'example_version_name',
+ 'plain_content': '<%body%>',
+ 'subject': '<%subject%>',
+ 'template_id': 'ddb96bbc-9b92-425e-8979-99464621b543'
+}";
+var template_id = "test_url_param";
+dynamic response = sg.client.templates._(template_id).versions.post(requestBody: data);
+Console.WriteLine(response.StatusCode);
+Console.WriteLine(response.Body.ReadAsStringAsync().Result);
+Console.WriteLine(response.Headers.ToString());
+Console.ReadLine();
+
+////////////////////////////////////////////////////////
+// Edit a transactional template version.
+// PATCH /templates/{template_id}/versions/{version_id}
+
+string data = @"{
+ 'active': 1,
+ 'html_content': '<%body%>',
+ 'name': 'updated_example_name',
+ 'plain_content': '<%body%>',
+ 'subject': '<%subject%>'
+}";
+var template_id = "test_url_param";
+var version_id = "test_url_param";
+dynamic response = sg.client.templates._(template_id).versions._(version_id).patch(requestBody: data);
+Console.WriteLine(response.StatusCode);
+Console.WriteLine(response.Body.ReadAsStringAsync().Result);
+Console.WriteLine(response.Headers.ToString());
+Console.ReadLine();
+
+////////////////////////////////////////////////////////
+// Retrieve a specific transactional template version.
+// GET /templates/{template_id}/versions/{version_id}
+
+var template_id = "test_url_param";
+var version_id = "test_url_param";
+dynamic response = sg.client.templates._(template_id).versions._(version_id).get();
+Console.WriteLine(response.StatusCode);
+Console.WriteLine(response.Body.ReadAsStringAsync().Result);
+Console.WriteLine(response.Headers.ToString());
+Console.ReadLine();
+
+////////////////////////////////////////////////////////
+// Delete a transactional template version.
+// DELETE /templates/{template_id}/versions/{version_id}
+
+var template_id = "test_url_param";
+var version_id = "test_url_param";
+dynamic response = sg.client.templates._(template_id).versions._(version_id).delete();
+Console.WriteLine(response.StatusCode);
+Console.WriteLine(response.Body.ReadAsStringAsync().Result);
+Console.WriteLine(response.Headers.ToString());
+Console.ReadLine();
+
+////////////////////////////////////////////////////////
+// Activate a transactional template version.
+// POST /templates/{template_id}/versions/{version_id}/activate
+
+var template_id = "test_url_param";
+var version_id = "test_url_param";
+dynamic response = sg.client.templates._(template_id).versions._(version_id).activate.post();
+Console.WriteLine(response.StatusCode);
+Console.WriteLine(response.Body.ReadAsStringAsync().Result);
+Console.WriteLine(response.Headers.ToString());
+Console.ReadLine();
+