Get a list of open shift assignments
URL: GET /api/v1/openshiftassignments[?startDate=<start_date>][&endDate=<end_date>]
Content: None
Returns: A list of Open Shift Assignments filtered by start_date and end_date, if supplied.
Get open shift assignment by ID
URL: GET /api/v1/openshiftassignments/<open_shift_assignment_id>
Content: None
Returns: A single Open Shift Assignment whose ID is open_shift_assignment_id.
Create an open shift
URL: POST /api/v1/openshiftassignments
Content: The Open Shift Assignment to create.
Returns: The Open Shift Assignment created.
Update an open shift
URL: PUT /api/v1/openshiftassignments
Content: The Open Shift Assignment to update.
Returns: The Open Shift Assignment updated.
Delete an open shift by ID
URL: DELETE /api/v1/openshiftassignments/<open_shift_assignment_id>
Content: None
Returns: None
Example Code
public int ReadRequiredNumOfEmployeesForOpenShifts(string accessToken, DateTime start, DateTime end)
{
int totalEmployees = 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/openshiftassignments?startDate=" + start.ToString("yyyy-mm-dd") + "&endDate=" + end.ToString("yy-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 increment the total employees.
if (( (HttpWebResponse) webResponse).StatusCode == HttpStatusCode.OK)
{
var reader = new StreamReader(webResponse.GetResponseStream());
dynamic openShiftArray = JsonConvert.DeserializeObject<dynamic>(reader.ReadToEnd());
// If the returned array contains more than one open shift, increment the total number of required employees by the number in the current open shift.
for (int length = 0; length < openShiftArray.Count; length++)
{
totalEmployees += (int) openShiftArray[length].RequiredCount;
}
reader.Close();
}
}
}
catch (WebException e)
{
// An error occurred in the call -- handle appropriately
Console.WriteLine(e);
}
return totalEmployees;
}
function getRequiredNumOfEmployeesForOpenShifts(accessToken, start, end, callback)
{
// URL of API to invoke
var serviceUrl = "https://app.snapschedule365.com/api/v1/openshiftassignments?startDate=" + start.toDateString() + "&endDate=" + end.toDateString();
// 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 openShiftArray = JSON.parse(request.responseText);
if (openShiftArray.length == 0)
{
callback(null);
}
// If the returned array contains more than one open shift assignments, increment the total number of employees required.
else
{
var totalEmployees = 0;
for (length = 0; length < openShiftArray.length; length++)
{
totalEmployees +=openShiftArray[length].RequiredCount;
}
callback(totalEmployees);
}
}
else
{
alert("HTTP status: " + request.status + "\n" + request.responseText);
}
}
}
// Send the request
request.send();
}