These samples cannot be used as they are not suitable for production code.
C# Sample
/NB: This is not production Code static void Main(string[] args) { string baseUrl = "http://[API URL]/api/[ver]/"; string apikey = "xxx-xxx"; int companyId = 0; string userName = "[email protected]"; string password = "xx"; var requestUrl = baseUrl + "customer/get?APIKey=" + apikey + "&companyid=" + companyId; var req = WebRequest.Create(requestUrl); //Option 1 to authenticate req.Credentials = new NetworkCredential(userName, password); //Option 2 to authenticate //string encodedCredentials; //encodedCredentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(myBusinessUserName + ":" + myBusinessPassword)); //req.Headers.Add("Authorization", "Basic " + encodedCredentials); req.Method = "GET"; try { var response = req.GetResponse(); if (response != null) { var responseStream = response.GetResponseStream(); if (responseStream != null) { var resultString = new StreamReader(responseStream).ReadToEnd(); var retrievedData = "Data: " + resultString + Environment.NewLine; Console.WriteLine(retrievedData); } } } catch (WebException ex) { HttpWebResponse errorResponse = ex.Response as HttpWebResponse; Console.WriteLine("StatusCode: " + errorResponse.StatusCode); Console.WriteLine("StatusMessage: " + errorResponse.StatusDescription); } Console.Read(); }
Javascript / JqQuery Sample
var baseUrl = 'http://[API URL]/api/[ver]/'; function getAuthorisation() { return "Basic " + $.base64Encode($('#txtUsername').val() + ":" + $('#txtPassword').val()); } function getCompanyId() { return $('#txtCompanyId').val(); } function getAPIKey() { return $('#txtApiKey').val(); } function GetTransactions() { $.support.cors = true; $.ajax({ type: "GET", contentType: "application/json; charset=utf-8", url: baseUrl + "/customer/Get?apikey=" + getAPIKey() + "&companyid=" + getCompanyId(), beforeSend: function (xhr) { xhr.setRequestHeader("Authorization", getAuthorisation()); }, success: function (data) { //Do something }, error: function (data) { //Do something else } }); }