API: Code Examples

PHP

The example below includes a cURL library-based PHP script which performs a request and a page containing a few API call examples based on this script; including authorization, getting a list of platforms, getting a device list by platform, creating a schedule and a notification group.

request.php

This script contains a main request function, based on a PHP cURL library, which calls API methods and displays a JSON object as a result


<?php
 // constant Dotcom-Monitor API v.1 address
 $API_URL = 'https://api.dotcom-monitor.com/config_api_v1/';
 // $action - dynamic url part
 // $method - HTTP method
 // $data - POST data, 'null' for GET request
 function Request($action, $method, $data) {
 // accessing global variable
 global $API_URL;
 // setting request url (merging "constant" and "dynamic" part)
 $ch = curl_init($API_URL . $action);
 // setting HTTP method
 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
 // return string
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
 // igroring SSL certificate
 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
 // Cookie management
 curl_setopt($ch, CURLOPT_COOKIEFILE, 'D:\PhpExample\cookie.txt');
 curl_setopt($ch, CURLOPT_COOKIEJAR, 'D:\PhpExample\cookie.txt');
 // creating request header array
 $headers = array('Content-Type: application/json');
 // checking if 'POST' method
 if($method === 'POST' && $data != null)
 {
 // encode input data to json
 $data_string = json_encode($data);
 // setting POST data
 curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
 // setting content length header
 array_push($headers, 'Content-Length: ' . strlen($data_string));
 }
 // setting headers
 curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
 // making request
 $result = curl_exec($ch);
 // closing connection
 curl_close($ch);
 // displaying response
 echo $result;
 // returning deserialized json data as object
 return json_decode($result);
 }
 ?>

 

 

page.php

Page contains examples of Authorization, listing resources, device creation and simple management of notification groups and templates.


<!-- including request function -->
 <?php include 'request.php'; ?>
 <!DOCTYPE html>
 <!-- css styles to make page readable -->
 <head>
 <style type="text/css">
 .request
 {
 background-color: #D3DEE2;
 font-weight: bold;
 padding: 8px;
 }
 .response
 {
 background-color: #EFEFEF;
 border: 1px solid #1D4982;
 margin-bottom: 25px;
 overflow: auto;
 padding: 5px;
 }
 .monitor
 {
 float: left;
 width: 215px;
 overflow: hidden;
 text-overflow: ellipsis;
 height: 22px;
 }
 .radio_block
 {
 float: left;
 width: 100px;
 overflow: hidden;
 }
 .form_param
 {
 border-bottom: 1px solid #C0C0C0;
 padding-top: 10px;
 clear: both;
 font-weight: bold;
 overflow: hidden;
 margin-bottom: 5px;
 }
 fieldset { background-color: #F4F8FF; }
 fieldset legend {
 font-weight: bold;
 font-size: 1.2em;
 }
 </style>
 </head>
 <body>
 <h1><?php echo $API_URL; ?></h1>
 <!-- Performing Log on and displaying result -->
 <div class="request">Log on</div>
 <div class="response">
 <?php
 $credentials = array("UserName" => "your_username", "Password" => "your_password");
 Request('login', "POST", $credentials); // making login request with credentials (authorization)
 ?>
 </div>
 <!-- Requesting platforms information and displaying result -->
 <div class="request">Get platforms</div>
 <div class="response">
 <?php
 // get all platforms
 $result = Request('platforms', "GET", null);
 // adding received data into a variable for further usage
 $platforms = $result;
 ?>
 </div>
 <!-- Requesting device list by each available platform and displaying result -->
 <div class="request">Devices by platform</div>
 <div class="response">
 <?php
 // variable for any first ServerView device, if available
 $device_id = 0;
 // iterating through all platforms
 foreach ($platforms as &$platform) {
 echo '<strong>' . $platform -> Name . '</strong>:<br />';
 //requesting devices for platfotm
 $result = Request("devices/" . $platform -> Name, "GET", null);
 echo '<br />';
 // checking for ServerView platform
 if ($platform -> Id == 1)
 {
 $max = sizeof($result);
 for($i = 0; $i < $max; $i++)
 // get first id and break loop
 {
 $device_id = $result[$i];
 break;
 }
 }
 }
 echo '</div>';
 if ($device_id > 0)
 {
 echo '<div class="request">Edit device with id: ' . $device_id . '</div>';
 echo '<div class="response">Load:<br />';
 // loading device by id
 $device = Request("device/" . $device_id, "GET", null);
 echo '</div>';
 echo '<div class="response">Save:<br />';
 // changing device name from "device_name" to "device_name (edited)"
 $device -> Name = $device -> Name . " (edited)";
 // save edited device
 Request("device/" . $device_id, "POST", $device);
 echo '</div>';
 }
 ?>

<!-- before we can create device, we have to receive required device properties -->
 <h2>Create device</h2>
 <div class="request">Locations for ServerView</div>
 <div class="response"><?php $locations = Request('locations/serverview', "GET", null); ?></div>
 <div class="request">Frequencies for ServerView</div>
 <div class="response"><?php $frequencies = Request('frequencies/serverview', "GET", null); ?></div>
 <div class="request">Get schedulers</div>
 <div class="response"><?php $schedulers = Request('schedulers', "GET", null); ?></div>
 <div class="request">Get Notification Groups</div>
 <div class="response"><?php $groups = Request('groups', "GET", null); ?></div>
 <div class="request">Get Filters</div>
 <div class="response"><?php $filters = Request('filters', "GET", null); ?></div>

<br />
 <!-- listing previously requested data -->
 <fieldset>
 <legend>Create device</legend>
 <form action="example.php?create_device=true" method="post">
 <?php
 echo '<div class="form_param">Locations</div>';
 foreach($locations as $location) {
 echo '<div class="monitor"><input type="checkbox" name="locations[]" value="' . $location -> Id . '" />' . $location -> Name . '</div>';
 }
 echo '<div class="form_param">Frequency</div>';
 foreach($frequencies as $frequency) {
 echo '<div class="radio_block"><input type="radio" name="frequency" value="' . $frequency . '" />' . $frequency . '</div>';
 }
 echo '<div class="form_param">Filter</div>';
 foreach($filters as $filter) {
 echo '<div class="radio_block"><input type="radio" name="filter" value="' . $filter . '" />' . $filter . '</div>';
 }
 echo '<div class="form_param">Scheduler</div>';
 foreach($schedulers as $scheduler) {
 echo '<div class="radio_block"><input type="radio" name="scheduler" value="' . $scheduler . '" />' . $scheduler . '</div>';
 }
 echo '<div class="form_param">Notifications</div>';
 foreach($groups as $group) {
 echo '<input type="checkbox" name="notifications[]" value="' . $group . '" />' . $group . ' - Time Shift: ';
 echo '<input type="text" name="notification' . $group . '" value="10" /> min <br />';
 }
 echo '<div class="form_param">Device name</div>';
 echo '<input type="text" name="device_name" value="" />';
 echo '<div class="form_param">Notification email</div>';
 echo '<input type="text" name="email" value="" />';
 // POST handler for device creation
 if ($_POST && !empty($_GET['create_device'])) {
 $notificationGroups = array();
 $locationsArray = array();
 if(!empty($_POST['notifications'])) {
 foreach($_POST['notifications'] as $check) {
 array_push( $notificationGroups, array("Id" => intval($check), "Time_Shift_Min" => $_POST['notification' . $check]));
 }
 }
 if(!empty($_POST['locations'])) {
 foreach($_POST['locations'] as $check) {
 array_push( $locationsArray, intval($check));
 }
 }
 // creating device object to be created
 $data = array(
 "Avoid_Simultaneous_Checks" => true,
 "False_Positive_Check" => false,
 "Send_Uptime_Alert" => false,
 "Platform_Id" => 1,
 "Locations" => $locationsArray,
 "Frequency" => intval($_POST['frequency']),
 "Filter_Id" => intval($_POST['filter']),
 "Scheduler_Id" => intval($_POST['scheduler']),
 "Name" => $_POST['device_name'],
 "Notifications" => array(
 "E_Mail_Flag" => true,
 "E_Mail_Address" => $_POST['email'],
 "Notification_Groups" => $notificationGroups
 )
 );
 echo '<br /><br /><div class="request">Result</div>';
 echo '<div class="response">';
 Request("devices?verb=PUT", "POST", $data); //creating device
 echo '</div>';
 }
 ?>
 <p>
 <input type="submit" value="Create device" />
 </p>
 </form>
 </fieldset>
 <h2>Create scheduler</h2>
 <fieldset>
 <legend>Create scheduler</legend>
 <form action="example.php?create_scheduler=true" method="post">
 <?php
 echo '<div class="form_param">Name</div>';
 echo '<input type="text" name="name" value="" />';
 echo '<div class="form_param">Description</div>';
 echo '<input type="text" name="description" value="" />';
 if ($_POST && !empty($_GET['create_scheduler'])) {
 // creating scheduler object
 $data = array(
 "Name" => $_POST['name'],
 "Description" => $_POST['description'],
 "Weekly_Intervals" => array(
 array(
 "Days" => array("Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"),
 "From_Min" => 0,
 "To_Min" => 1025,
 "Included" => true
 ), array(
 "Days" => array("Su", "Sa"),
 "From_Min" => 0,
 "To_Min" => 1139,
 "Included" => false
 ), array(
 "Days" => array("Su", "Mo", "Fr", "Sa"),
 "From_Min" => 120,
 "To_Min" => 240,
 "Included" => false
 )
 ),
 "Date_Time_Intervals" => array(
 "From" => 1358712000000,
 "To" => 1358798400000
 )
 );
 echo '<br /><br /><div class="request">Result</div>';
 echo '<div class="response">';
 Request("schedulers?verb=PUT", "POST", $data); //making create request
 echo '</div>';
 }
 ?>
 <p>
 <input type="submit" value="Create scheduler" />
 </p>
 </form>
 </fieldset>

<h2>Create notification group</h2>
 <fieldset>
 <legend>Create notification group</legend>
 <form action="example.php?create_group=true" method="post">
 <?php
 echo '<div class="form_param">Name</div>';
 echo '<input type="text" name="name" value="" />';
 if ($_POST && !empty($_GET['create_group'])) {
 // creating notification group with requered fields
 $data = array(
 "Name" => $_POST['name'],
 "Scheduler_Id" => 0
 );
 echo '<br /><br /><div class="request">Result</div>';
 echo '<div class="response">';
 Request("groups?verb=PUT", "POST", $data); //making request
 echo '</div>';
 }
 ?>
 <p>
 <input type="submit" value="Create notification group" />
 </p>
 </form>
 </fieldset>
 </body>
 </html>

 

C#

Given example written on C# contains the following patterns:

c#
Pattern
Code Line
Add new HTTP task 392
Create new Schedule 426
Create new SV Device 357
Device list by Platform 299
Edit Device 319
Get Frequencies 342
Get Monitors 334
Get notification groups 350
Login 262
Platforms listing 282
Schedule listing 419
ServerView (SV) Device by ID 315

using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Text;
using System.Web.Script.Serialization;
namespace example
{
class Program
{
class OperatioResult
{
public bool Success { get; set; }
public string Result { get; set; }
public override string ToString()
{
return String.Format("Success: {0}; Result: {1}", Success, Result);
}
}
class ErrorResult
{
public bool Success { get; set; }
public string[] ErrorDescription { get; set; }
public override string ToString()
{
return String.Join(Environment.NewLine, ErrorDescription);
}
}
class Platform
{
public int Id { get; set; }
public string Name { get; set; }
public bool Available { get; set; }
public override string ToString()
{
return String.Format("Id: {0}; Name: {1}; Available: {2}", Id, Name, Available);
}
}
class Monitor
{
public int Id { get; set; }
public string Name { get; set; }
public bool Available { get; set; }
public bool IsDeleted { get; set; }
public bool IsPrivate { get; set; }
public override string ToString()
{
return String.Format("Id: {0}; Name: {1}; Available: {2}; IsDeleted: {3}; IsPrivate: {4}",
Id, Name, Available, IsDeleted, IsPrivate);
}
}
class WeeklyInterval
{
public string[] Days { get; set; }
public int From_Min { get; set; }
public int To_Min { get; set; }
public bool Included { get; set; }
public override string ToString()
{
return String.Format("Days: [{0}]; From_Min: {1} (Time: {4}); To_Min: {2} (Time: {5}); Included: {3}",
String.Join(", ", Days), From_Min, To_Min, Included, TimeSpan.FromMinutes(From_Min), TimeSpan.FromMinutes(To_Min));
}
}
class DateTimeInterval
{
public long From { get; set; }
public long To { get; set; }
public override string ToString()
{
return String.Format("From: {0} (Time: {2}); To: {1} (Time: {3})",
From, To, UnixBaseTime.AddMilliseconds(From), UnixBaseTime.AddMilliseconds(To));
}
}
class AssignedToInfo
{
/// &lt;summary&gt;
/// read only
/// &lt;/summary&gt;
public int[] Devices { get; set; }
/// &lt;summary&gt;
/// read only
/// &lt;/summary&gt;
public int[] Notification_Groups { get; set; }
public override string ToString()
{
return String.Format("Devices: [{0}]; Notification_Groups: [{1}]",
String.Join(", ", Devices.Select(id =&gt; id.ToString()).ToArray()),
String.Join(", ", Notification_Groups.Select(id =&gt; id.ToString()).ToArray()));
}
}
class Scheduler
{
public int Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public WeeklyInterval[] Weekly_Intervals { get; set; }
public DateTimeInterval[] Date_Time_Intervals { get; set; }
public AssignedToInfo Assigned_To { get; set; }
public override string ToString()
{
return String.Format("Id: {0}; Name: {1}; Description: {2}; Weekly_Intervals: [{3}]; Date_Time_Intervals: [{4}]; AssignedToInfo: {5}",
Id, Name, Description,
String.Join(", ", Weekly_Intervals.Select(wi =&gt; wi.ToString()).ToArray()),
String.Join(", ", Date_Time_Intervals.Select(dti =&gt; dti.ToString()).ToArray()), Assigned_To);
}
}
class SiteNotifyGroup
{
public int Id { get; set; }
public int Time_Shift_Min { get; set; }
}
class Notifications
{
public bool E_Mail_Flag { get; set; }
public string E_Mail_Address { get; set; }
public int E_Mail_TimeInterval_Min { get; set; }
public bool WL_Device_Flag { get; set; }
public string WL_Device_Email_Address { get; set; }
public int WL_Device_TimeInterval_Min { get; set; }
public bool Pager_Flag { get; set; }
public string Pager_Area_Code { get; set; }
public string Pager_Phone { get; set; }
public string Pager_Num_Code { get; set; }
public int Pager_TimeInterval_Min { get; set; }
public bool Phone_Flag { get; set; }
public string Phone_Area_Code { get; set; }
public string Phone_Phone { get; set; }
public int Phone_TimeInterval_Min { get; set; }
public bool SMS_Flag { get; set; }
public string SMS_Phone { get; set; }
public int SMS_TimeInterval_Min { get; set; }
public bool Script_Flag { get; set; }
public string Script_Batch_File_Name { get; set; }
public int Script_TimeInterval_Min { get; set; }
public int SNMP_TimeInterval_Min { get; set; }
public SiteNotifyGroup[] Notification_Groups { get; set; }
}
class ServerViewDevice
{
public int Id { get; set; }
public int Platform_Id { get; set; }
public string Name { get; set; }
public int Number_Of_Tasks { get; set; }
public string Status_Description { get; set; }
public bool Postpone { get; set; }
public bool Send_Uptime_Alert { get; set; }
public int Owner_Device_Id { get; set; }
public int Frequency { get; set; }
public int Filter_Id { get; set; }
public int Scheduler_Id { get; set; }
public Notifications Notifications { get; set; }
public bool Avoid_Simultaneous_Checks { get; set; }
public bool False_Positive_Check { get; set; }
public int Alert_Silence_Min { get; set; }
public int[] Locations { get; set; }
}
class TaskType
{
public int Id { get; set; }
public string Name { get; set; }
}
class NameValuePair
{
public string Name { get; set; }
public string Value { get; set; }
}
class HTTPTask
{
public int Device_Id { get; set; }
public int Id { get; set; }
public int Task_Type_Id { get; set; }
public string Name { get; set; }
public int Timeout { get; set; }
public string RequestType { get; set; }
public string Url { get; set; }
public string Keyword1 { get; set; }
public string Keyword2 { get; set; }
public string Keyword3 { get; set; }
public string UserName { get; set; }
public string UserPass { get; set; }
public bool FullPageDownload { get; set; }
public bool Download_Html { get; set; }
public bool Download_Frames { get; set; }
public bool Download_StyleSheets { get; set; }
public bool Download_Scripts { get; set; }
public bool Download_Images { get; set; }
public bool Download_Objects { get; set; }
public bool Download_Applets { get; set; }
public bool Download_Additional { get; set; }
public NameValuePair[] GetParams { get; set; }
public NameValuePair[] PostParams { get; set; }
public NameValuePair[] HeaderParams { get; set; }
string PrepareScript { get; set; }
}
enum RequestMethod
{
GET,
POST
}
private static CookieContainer container;
public static readonly DateTime UnixBaseTime = new DateTime(1970, 1, 1, 0, 0, 0, 0);
// setting up request function
private static string Request(string action, RequestMethod requestType, string data)
{
WebRequest request = WebRequest.Create("https://api.dotcom-monitor.com/config_api_v1/" + action);
request.Method = requestType.ToString();
((HttpWebRequest) request).CookieContainer = container;
if (requestType == RequestMethod.POST)
{
string postData = data;
if (postData.Length &gt; 0)
{
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
request.ContentType = "application/json";
request.ContentLength = byteArray.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
}
else
{
request.ContentLength = 0;
}
}
try
{
using (var response = request.GetResponse())
{
using (var stream = response.GetResponseStream())
{
if (stream != null)
{
using (var reader = new StreamReader(stream))
{
return reader.ReadToEnd();
}
}
}
}
}
catch (Exception ex)
{
using (var stream = ex.Response.GetResponseStream())
{
using (var reader = new StreamReader(stream))
{
throw new Exception(reader.ReadToEnd());
}
}
}
return String.Empty;
}

static void Main()
{
// ignore certificate errors
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
// initialize cookie container
container = new CookieContainer();
// initialize javascript serializer
var serializer = new JavaScriptSerializer();
// login
Console.WriteLine("==Login==");
string resultStr;
try
{
resultStr = Request("login", RequestMethod.POST,
serializer.Serialize(
new {
UserName = "1",
Password = "1"
}
));
var result = serializer.Deserialize&lt;OperatioResult&gt;(resultStr);
Console.WriteLine(result.ToString());
}
catch (Exception ex)
{
var err = serializer.Deserialize&lt;ErrorResult&gt;(ex.Message);
Console.WriteLine(err.ToString());
}
// get platforms
Console.WriteLine("==Get platforms==");
IEnumerable&lt;Platform&gt; platforms = null;
try
{
resultStr = Request("platforms", RequestMethod.GET, String.Empty);
platforms = serializer.Deserialize&lt;Platform[]&gt;(resultStr);
}
catch(Exception ex)
{
var err = serializer.Deserialize&lt;ErrorResult&gt;(ex.Message);
Console.WriteLine(err.ToString());
}
foreach (var platform in platforms)
{
Console.WriteLine(platform);
}
// get devices by platform
Console.WriteLine("==Get devices by platform==");
int svDeviceId = 0;
foreach (var platform in platforms.Where(p =&gt; p.Available))
{
resultStr = Request(String.Format("devices/{0}", platform.Name), RequestMethod.GET, String.Empty);
var ds = serializer.Deserialize&lt;int[]&gt;(resultStr);
foreach (var id in ds)
{
if (svDeviceId == 0 &amp;&amp; platform.Id == 1)
{
svDeviceId = id;
}
Console.WriteLine("{0} - {1}", platform.Name, id);
}
}
// get ServerView device by id
Console.WriteLine("==Get device by id==");
resultStr = Request(String.Format("device/{0}", svDeviceId), RequestMethod.GET, String.Empty);
var device = serializer.Deserialize&lt;ServerViewDevice&gt;(resultStr);
// edit device
Console.WriteLine("==Edit device==");
device.Name = device.Name + " (edited)";
try
{
resultStr = Request(String.Format("device/{0}", device.Id), RequestMethod.POST,
serializer.Serialize(device));
var result = serializer.Deserialize&lt;OperatioResult&gt;(resultStr);
Console.WriteLine(result.ToString());
}
catch (Exception ex)
{
var err = serializer.Deserialize&lt;ErrorResult&gt;(ex.Message);
Console.WriteLine(err.ToString());
}
// get monitors
Console.WriteLine("==Get monitors==");
IEnumerable&lt;Monitor&gt; monitors = serializer.Deserialize&lt;Monitor[]&gt;(Request(String.Format("locations/{0}", device.Platform_Id),
RequestMethod.GET, String.Empty));
foreach (var monitor in monitors)
{
Console.WriteLine(monitor);
}
// get frequencies
Console.WriteLine("==Get frequencies==");
var frequencies = serializer.Deserialize&lt;int[]&gt;(Request(String.Format("frequencies/{0}", device.Platform_Id),
RequestMethod.GET, String.Empty));
foreach (var frequency in frequencies)
{
Console.WriteLine(frequency);
}
// get notification groups
Console.WriteLine("==Get notification groups==");
var ngs = serializer.Deserialize&lt;int[]&gt;(Request("groups", RequestMethod.GET, String.Empty));
foreach (var ng in ngs)
{
Console.WriteLine(ng);
}
// create new device
Console.WriteLine("==Create device==");
device = new ServerViewDevice
{
Platform_Id = platforms.Single(p =&gt; p.Name.ToLower() == "serverview").Id,
Name = "new device",
Frequency = frequencies[0],
Postpone = true,
Locations = monitors.Where(m =&gt; m.Available &amp;&amp; !m.IsPrivate &amp;&amp; (m.Id%2 == 0)).Select(m =&gt; m.Id).ToArray(),
Avoid_Simultaneous_Checks = true,
Notifications = new Notifications
{
E_Mail_Flag = false,
Pager_Flag = false,
Phone_Flag = false,
SMS_Flag = false,
Script_Flag = false,
WL_Device_Flag = false,
Notification_Groups = ngs.Take(1).Select(ng =&gt; new SiteNotifyGroup {Id = ng, Time_Shift_Min = 0 /*0 = Immediate*/}).ToArray()
}
};
int newDeviceId = 0;
try
{
resultStr = Request("devices?verb=PUT", RequestMethod.POST,
serializer.Serialize(device));
var result = serializer.Deserialize&lt;OperatioResult&gt;(resultStr);
newDeviceId = int.Parse(result.Result);
Console.WriteLine(result.ToString());
}
catch (Exception ex)
{
var err = serializer.Deserialize&lt;ErrorResult&gt;(ex.Message);
Console.WriteLine(err.ToString());
}
// add new HTTP task
Console.WriteLine("==Create HTTP task==");
resultStr = Request("tasktypes/" + device.Platform_Id, RequestMethod.GET, String.Empty);
var tts = serializer.Deserialize&lt;TaskType[]&gt;(resultStr);
var httpTT = tts.Single(tt =&gt; tt.Name.ToLower() == "http");
var task = new HTTPTask
{
Device_Id = newDeviceId,
Task_Type_Id = httpTT.Id,
Name = "New HTTP Task",
Timeout = 100500,
RequestType = "GET",
Url = "amazon.de"
};
try
{
resultStr = Request("tasks?verb=PUT", RequestMethod.POST,
serializer.Serialize(task));
var result = serializer.Deserialize&lt;OperatioResult&gt;(resultStr);
Console.WriteLine(result.ToString());
}
catch (Exception ex)
{
var err = serializer.Deserialize&lt;ErrorResult&gt;(ex.Message);
Console.WriteLine(err.ToString());
}

// get schedulers
Console.WriteLine("==Get schedulers==");
var ss = serializer.Deserialize&lt;int[]&gt;(Request("schedulers", RequestMethod.GET, String.Empty));
foreach (var s in ss)
{
Console.WriteLine(serializer.Deserialize&lt;Scheduler&gt;(Request("scheduler/" + s, RequestMethod.GET, String.Empty)));
}
// create new schedulers
Console.WriteLine("==Create new schedulers==");
var scheduler = new Scheduler
{
Name = "New",
Description = "descr",
Date_Time_Intervals = new[]
{
new DateTimeInterval
{
From = (long) (new DateTime(2013, 2, 2, 2, 0, 0, 0) - UnixBaseTime).TotalMilliseconds,
To = (long) (new DateTime(2013, 2, 2, 2, 30, 0, 0) - UnixBaseTime).TotalMilliseconds,
}
},
Weekly_Intervals = new[]
{
new WeeklyInterval
{
Days = new[] {"mo", "tu", "sa"},
From_Min = (int) new TimeSpan(7, 0, 0).TotalMinutes,
To_Min = (int) new TimeSpan(13, 0, 0).TotalMinutes,
Included = false
}
}
};
try
{
resultStr = Request("schedulers?verb=PUT", RequestMethod.POST,
serializer.Serialize(scheduler));
var result = serializer.Deserialize&lt;OperatioResult&gt;(resultStr);
Console.WriteLine(result.ToString());
}
catch (Exception ex)
{
var err = serializer.Deserialize&lt;ErrorResult&gt;(ex.Message);
Console.WriteLine(err.ToString());
}
Console.ReadKey();
}
}
}