Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.