Skip to content

Instantly share code, notes, and snippets.

@lfepp
Last active May 25, 2016 16:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lfepp/cf290058fb8afaef7cfde155df8434d1 to your computer and use it in GitHub Desktop.
Save lfepp/cf290058fb8afaef7cfde155df8434d1 to your computer and use it in GitHub Desktop.
Create a PagerDuty maintenance window using C#
using System;
using System.IO;
using System.Net;
using System.Text;
namespace Examples.System.Net
{
public class WebRequestPostExample
{
public static void Main()
{
var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://ENTER_YOUR_SUBDOMAIN_HERE.pagerduty.com/api/v1/maintenance_windows/");
httpWebRequest.ContentType = "application/json";
httpWebRequest.Method = "POST";
httpWebRequest.Headers["Authorization"] = "Token token=ENTER_API_KEY_HERE";
string UserId = "ENTER_USER_ID_HERE";
string ServiceId = "ENTER_SERVICE_ID_HERE";
using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
{
string json = "{\"maintenance_window\": {\"start_time\":\"2016-06-17\"," +
"\"end_time\":\"2016-06-20\"," +
"\"description\":\"test\"," +
"\"service_ids\":[\"" + ServiceId + "\"]}," +
"\"requester_id\": \"" + UserId + "\"}";
streamWriter.Write(json);
streamWriter.Flush();
streamWriter.Close();
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var result = streamReader.ReadToEnd();
Console.WriteLine(result);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment