Get a list of Punches
URL: GET /api/v1/punches[?startDate=<start_date>][&endDate=<end_date>]
Content: None
Returns: A list of Punches filtered by start_date and end_date, if supplied.
Get a punch by ID
URL: GET /api/v1/punches/<punch_id>
Content: None
Returns: A single Punch whose ID is punch_id.
Create a punch
URL: POST /api/v1/punches
Content: The Punch to create.
Returns: The Punch created.
Update a punch
URL: PUT /api/v1/punches
Content: The Punch to update.
Returns: The Punch updated.
Delete a punch by ID
URL: DELETE /api/v1/punches/<punch_id>
Content: None
Returns: None
Create punches in bulk
URL: POST /api/v1/punches/bulk
Content: A list of the Punches to create.
Returns: A list of the Punches created.
Update punches in bulk
URL: PUT /api/v1/punches/bulk
Content: A list of the Punches to update.
Returns: A list of the Punches updated.
Delete punches in bulk
URL: DELETE /api/v1/punches/bulk
Content: A list of Punches to delete.
Returns: None
Example Code
public int ReadNumberOfCurrentlyPunchedInEmployees(string accessToken)
{
int employeeCount = 0;
// Create web request to call API (be sure to add access token to request header)
var webRequest = (HttpWebRequest) WebRequest.Create(@"https://app.snapschedule365.com/api/v1/punches?startDate=" + DateTime.Today.ToString("yyyy-mm-dd") + "&endDate=" + DateTime.Today.ToString("yyyy-mm-dd"));
webRequest.Method = "GET";
webRequest.Accept = @"application/json";
webRequest.Headers.Add("Authorization", "Bearer " + accessToken);
webRequest.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
try
{
using (WebResponse webResponse = webRequest.GetResponse())
{
// If the web response is OK, then read the reply and extract the punch records
if (((HttpWebResponse) webResponse).StatusCode == HttpStatusCode.OK)
{
var reader = new StreamReader(webResponse.GetResponseStream());
dynamic punchArray = JsonConvert.DeserializeObject<dynamic>(reader.ReadToEnd());
// Loops through all employee punch records
foreach (dynamic punch in punchArray)
{
// Used to determine whether or not a certain employee is punched in.
bool isPunchedIn = false;
List<dynamic> sortedPunchEntries = new List<dynamic>();
// Adds all punch entries that occur before the current time of day to the unsorted list of punch entries.
foreach (dynamic punchEntry in punch.PunchEntries)
{
if (punchEntry.PunchDate < DateTime.Now)
{
sortedPunchEntries.Add(punchEntry);
}
}
// Sort the list of punch entries by PunchDate.
sortedPunchEntries.Sort(Comparer<dynamic>.Create((dynamic a, dynamic b) =>
{
return a.PunchDate.CompareTo(b.PunchDate);
}));
// Once the punch entries are sorted, determine whether or not a certain employee is punched in.
foreach (dynamic entry in sortedPunchEntries)
{
// PunchTypeValue of 1=Punched In, 2=Punched Out
isPunchedIn = (entry.PunchTypeValue == 1) ? true : false;
}
// If the employee is punched in, increment the employee counter by one.
if (isPunchedIn == true)
{
employeeCount++;
}
}
reader.Close();
}
}
}
catch (WebException e)
{
// An error occurred in the call -- handle appropriately
Console.WriteLine(e);
}
return employeeCount;
}
function getNumberOfCurrentlyPunchedInEmployees(accessToken, callback)
{
var employeeCount = 0;
// format today's date
var date = new Date().toDateString();
// URL of API to invoke
var serviceUrl = "https://app.snapschedule365.com/api/v1/punches?startDate=" + date + "&endDate=" + date;
// Create the request
var request = new XMLHttpRequest();
// Build the request
request.open("GET", serviceUrl, true);
request.setRequestHeader("accept", "application/json");
// Add access token to request
request.setRequestHeader("Authorization", "Bearer " + accessToken);
// Set up request status handler to invoke the callback function when complete
request.onreadystatechange = function()
{
if (request.readyState == 4)
{
if (request.status == 200)
{
var punchArray = JSON.parse(request.responseText);
if (punchArray.length == 0)
{
callback(null);
}
// Loops through all employee punch records
else
{
for (i = 0; i < punchArray.length; i++)
{
var punch = punchArray[i];
// Used to determine whether or not a certain employee is punched in.
var isPunchedIn = false;
var sortedPunchEntries = new Array();
// Adds all punch entries that occur before the current time of day to the unsorted list of punch entries.
for (j = 0; j < punch.PunchEntries.length; j++)
{
var punchEntry = punch.PunchEntries[j];
var punchTime = new Date(punchEntry.PunchDate);
if (punchTime < new Date())
{
sortedPunchEntries.push(punchEntry);
}
}
// Sort the list of punch entries by PunchDate.
sortedPunchEntries.sort(function(a, b)
{
return new Date(b.PunchDate).valueOf() - new Date(a.PunchDate).valueOf();
});
// Once the punch entries are sorted, determine whether or not a certain employee is punched in.
for (k = 0; k < sortedPunchEntries.length; k++)
{
var punchEntry = sortedPunchEntries[k];
// PunchTypeValue of 1=Punched In, 2=Punched Out
isPunchedIn = (punchEntry.PunchTypeValue == 1) ? true : false;
}
// If the employee is punched in, increment the employee counter by one.
if (isPunchedIn == true)
{
employeeCount++;
}
}
callback(employeeCount);
}
}
else
{
alert("HTTP status: " + request.status + "\n" + request.responseText);
}
}
}
// Send the request
request.send();
}