Authentication

URL

https://{company}.bluecamroo.com/api/Authentication/Login

HTTP Method

POST

Parameters

Username: Your BlueCamroo System Administrator email address used for login.

Password: The password associated with your BlueCamroo login.

Data Return

A session id and error message

Example


public class LoginSession
{
   public string SessionId { get; set; }
   public string Error { get; set; }
}

public static CookieContainer cookies = null;
public static string baseUrl;
public static bool isAuthenticated = false;

static void Main(string[] args)
{
	string url = baseUrl + "/authentication/login";
	cookies = new CookieContainer();
	string data = "username=myemail@abc.com&password=mypassword";
	string result = "";

	int status = WebRequest("POST", url, data, ref result, "application/x-www-form-urlencoded");

	if (status == (int)HttpStatusCode.OK)
	{
		JavaScriptSerializer serializer = new JavaScriptSerializer();
		LoginSession session = (LoginSession)serializer.Deserialize(result, typeof(LoginSession));

		if (session.Error == "")
			isAuthenticated = true;
		else
			Console.Write(session.Error);
	}
}

public static int WebRequest(string method, string url, string data, ref string result, string contentType)
{
	HttpWebRequest webRequest = (HttpWebRequest)System.Net.WebRequest.Create(url);
	webRequest.Method = method;
	webRequest.ContentType = contentType;
	webRequest.CookieContainer = cookies;

	if (!String.IsNullOrEmpty(data))
	{
		byte[] postData = Encoding.UTF8.GetBytes(data);

		webRequest.ContentLength = postData.Length;
		Stream stream = webRequest.GetRequestStream();
		stream.Write(postData, 0, postData.Length);
		stream.Close();
	}

	int status;

	try
	{
		HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();

		Stream stream = webResponse.GetResponseStream();
		StreamReader sr = new StreamReader(stream);
		result = sr.ReadToEnd();
		sr.Close();

		status = (int)webResponse.StatusCode;
	}
	catch (WebException ex)
	{
		Stream stream = ex.Response.GetResponseStream();
		StreamReader sr = new StreamReader(stream);
		result = sr.ReadToEnd();
		sr.Close();

		status = (int)((HttpWebResponse)ex.Response).StatusCode;
	}
	catch (Exception ex)
	{
		status = (int)HttpStatusCode.ServiceUnavailable;
	}

	return status;
}