Get a list of shift premium policies
URL: GET /api/v1/shiftpremiumpolicies
Content: None
Returns: A list of Shift Premium Policies.
Get a shift premium policy by ID
URL: GET /api/v1/shiftpremiumpolicies/<shift_premium_policy_id>
Content: None
Returns: A single Shift Premium Policy whose ID is shift_premium_policy_id.
Example Code
public string ReadFirstShiftPremiumPolicyDescription(string accessToken)
{
string shiftPremiumPolicy = 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/shiftpremiumpolicies");
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 first shift premium policy's description
if (((HttpWebResponse)webResponse).StatusCode == HttpStatusCode.OK)
{
var reader = new StreamReader(webResponse.GetResponseStream());
dynamic policyArray = JsonConvert.DeserializeObject<dynamic>(reader.ReadToEnd());
// If the returned array contains more than one shift premium policy, extract the first policy's description.
if (policyArray.Count > 0)
{
shiftPremiumPolicy = policyArray[0].Description;
}
reader.Close();
}
}
}
catch (WebException e)
{
// An error occurred in the call -- handle appropriately
Console.WriteLine(e);
}
return shiftPremiumPolicy;
}
function getFirstShiftPremiumPolicyDescription(accessToken, callback)
{
// URL of API to invoke
var serviceUrl = "https://app.snapschedule365.com/api/v1/shiftpremiumpolicies";
// 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 shiftPremiumPolicyArray = JSON.parse(request.responseText);
// If the returned array contains more than one shift premium policy, extract the first policy's description
if (shiftPremiumPolicyArray.length > 0)
{
callback(shiftPremiumPolicyArray[0].Description);
}
else
{
callback(null);
}
}
else
{
alert("HTTP status: " + request.status + "\n" + request.responseText);
}
}
}
// Send the request
request.send();
}