Jitbit Integration with .NET

Deliver awesome support to your customers. Jitbit Helpdesk ticketing system is a simple, powerful and easy to deal with. We can either host it in on-premise or cloud-host.There was a recent requuest from one of my client to come up with a simple ticketing system where business can start operating quickly and integrate it with there clinet facing .NET application.The real beauty was , the interface it expose where we can integrate with our Entraprise Apllications. I am going to share few code samples that will be helpful.

Please see some helper methods first:

        public string BuildRequest(string method, IEnumerable<KeyValuePair<string, string>> urlParameters)
        {
            var returnData = "{}";
            var querystring = new StringBuilder("?");
            if (urlParameters != null && urlParameters.Count() > 0)
            {
                foreach (var item in urlParameters)
                {
                    querystring.Append(item.Key + "=" + item.Value + "&");

                }
                querystring.Remove(querystring.Length - 1, 1);
            }
            else { querystring.Clear(); }
            return returnData;
        }
        private string ConstructHeader()
        {
            string credentials = new StringBuilder(_Username + ":" + _Password).ToString();
            return new StringBuilder("Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes(credentials))).ToString();
        }
        private HttpWebRequest ConstructRequest(string querystring = "")
        {
            HttpWebRequest ClientWebRequest = (HttpWebRequest)WebRequest.Create(_BaseAdress + querystring);
            IWebProxy proxy = ClientWebRequest.Proxy;
            if (proxy != null)
            {
                NetworkCredential cred = System.Net.CredentialCache.DefaultNetworkCredentials;
                proxy.Credentials = cred;
                WebRequest.DefaultWebProxy = proxy;
            }
            AddAuthenticationHeader(ClientWebRequest);
            ClientWebRequest.Accept = "Application/Json";
            ClientWebRequest.ContentType = "Application/Json";
            ClientWebRequest.Method = WebRequestMethods.Http.Get;
            return ClientWebRequest;
        }
        private HttpWebRequest ConstructRequest(string querystring = "")
        {
            var ClientWebRequest = (HttpWebRequest)WebRequest.Create(_BaseAdress + querystring);
            var proxy = ClientWebRequest.Proxy;
            if (proxy != null)
            {
                NetworkCredential cred = System.Net.CredentialCache.DefaultNetworkCredentials;
                proxy.Credentials = cred;
                WebRequest.DefaultWebProxy = proxy;
            }
            ClientWebRequest.Accept = "Application/Json";
            ClientWebRequest.ContentType = "Application/Json";
            ClientWebRequest.Method = WebRequestMethods.Http.Get;
            return ClientWebRequest;
        }

        private string ReadResponse(HttpWebResponse response)
        {
            string ResponseContent = null;
            using (var reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
            {
                ResponseContent = reader.ReadToEndAsync().Result;
            }
            return ResponseContent;
        }

Now Lets Make some API Calls:

         public JToken GetEntitiesByEmail(string userName)
        {
            var querystring = new Dictionary<string, string> { { "email", userName } };
            try
            {
                var response = this._helpDeskService.BuildRequest("UserByEmail", querystring);
                var result = JToken.Parse(response);
                return result;
            }
            catch (Exception ex)
            {
            }
        }
        public JToken GetEntitiesByUser( string userEmail)
        {
            var querystring = new Dictionary<string, string> { { "email", userEmail } };
            try
            {
                var response = this._helpDeskService.BuildRequest("UserByEmail", querystring);
                var result = JToken.Parse(response);
                var user = result.ToObject<HelpDeskUser>();
                querystring.Clear();
                querystring.Add("handledByUserID", user.UserID.ToString());
                return JToken.Parse(this._helpDeskService.ForwardGetRequest(entity, querystring));
            }
            catch (Exception ex)
            {
            }
        }
        public JToken GetHelpDeskTickets( string categoryid)
        {
            var querystring = new Dictionary<string, string>
            {
                { "mode", "unclosed"},
                { "categoryid", categoryid },
                { "count", "100" } 
            };
            try
            {
                var response = this._helpDeskService.BuildRequest("tickets", querystring);
                var result = JToken.Parse(response);
                return result;
            }
            catch (Exception ex)
            {
            }
        }
        public string GetCreatedUser()
        {
            var querystring = new Dictionary<string, string>
            {
                { "email", "jijo@me.com" },
                { "firstName", "Jijo" } ,
                { "lastName", "vg" } ,
                { "userName", "jijo" } ,
                { "sendWelcomeEmail", "true" }
            };
            try
            {
                var response = this._helpDeskService.HttpPostRequest("CreateUser", querystring);
                return response;
            }
            catch (Exception ex)
            {

            }
        }

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s