Get a list of shift assignments
URL: GET /api/v1/shiftassignments[?startDate=<start_date>][&endDate=<end_date>][&lastUpdated=<last_updated_date>]
Content: None
Returns: A list of Shift Assignments that are scheduled between start_date and end_date, and/or were last updated since last_updated_date, if supplied.
Get a shift assignment by ID
URL: GET /api/v1/shiftassignments/<shift_assignment_id>
Content: None
Returns: A single Shift Assignment whose ID is shift_assignment_id.
Create a shift assignment
URL: POST /api/v1/shiftassignments
Content: The Shift Assignment to create.
Returns: The Shift Assignment created.
Update a shift assignment
URL: PUT /api/v1/shiftassignments
Content: The Shift Assignment to update.
Returns: The Shift Assignment updated.
Delete a shift assignment by ID
URL: DELETE /api/v1/shiftassignments/<shift_assignment_id>
Content: None
Returns: None
Get a list of deleted shift assignments
URL: GET /api/v1/shiftassignments/deleted[?deletedSince=<deleted_since_date>]
Content: None
Returns: A list of empty Shift Assignments that have been deleted since deleted_since_date. Only the ID field will be populated, the other fields will be blank. If deleted_since_date is not provided, then today’s date will be used.
Create shift assignments in bulk
URL: POST /api/v1/shiftassignments/bulk
Content: A list of Shift Assignments to create.
Returns: A list of the Shift Assignments created.
Update shift assignments in bulk
URL: PUT /api/v1/shiftassignments/bulk
Content: A list of Shift Assignments to update.
Returns: A list of the Shift Assignments updated.
Delete shift assignments by ID in bulk
URL: DELETE /api/v1/shiftassignments/bulk
Content: A list of shift_assignment_ids (integers) that match the ID fields of Shift Assignments to delete.
Returns: None
Example Code
public string ReadFirstShiftAssignmentOfToday(string accessToken)
{
string shiftAssignment = string.Empty;
// 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/shiftassignments?startDate=" + System.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 today's first shift assignment.
if (((HttpWebResponse)webResponse).StatusCode == HttpStatusCode.OK)
{
var reader = new StreamReader(webResponse.GetResponseStream());
dynamic shiftAssignmentArray = JsonConvert.DeserializeObject<dynamic>(reader.ReadToEnd());
// If the returned array contains more than one shift assignment, extract the first assignment's shift description.
if (shiftAssignmentArray.Count > 0 && shiftAssignmentArray[0].Shift != null)
{
shiftAssignment = shiftAssignmentArray[0].Shift.Description;
}
reader.Close();
}
}
}
catch (WebException e)
{
// An error occurred in the call -- handle appropriately
Console.WriteLine(e);
}
return shiftAssignment;
}
function getFirstShiftAssignmentOfToday(accessToken, callback)
{
// URL of API to invoke and delivers only the year, month, and day of the date string.
var serviceUrl = "https://app.snapschedule365.com/api/v1/shiftassignments?startDate=" + new Date().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 shiftAssignmentArray = JSON.parse(request.responseText);
// If the returned array contains more than one shift assignment, extract today's first assignment.
if (shiftAssignmentArray.length > 0 && shiftAssignmentArray[0].Shift != null)
{
callback(shiftAssignmentArray[0].Shift.Description);
}
else
{
callback(null);
}
}
else
{
alert("HTTP status: " + request.status + "\n" + request.responseText);
}
}
}
// Send the request
request.send();
}