private long? CreateUser(User user, string email, string type) { if (string.IsNullOrWhiteSpace(type)) throw new MissingFieldException("User's type cannot be empty for zendesk."); string encodedEmail = HttpContext.Current.Server.UrlEncode(email); ZendeskApi_v2.ZendeskApi api = new ZendeskApi_v2.ZendeskApi(_ZenDeskPath, _ZenDeskUser, _ZenDeskApiKey, _ZenDeskLocal); // Double check if user is already created on zendesk... ZendeskApi_v2.Models.Users.GroupUserResponse responseOld = api.Users.SearchByEmail(encodedEmail); if (responseOld != null && responseOld.Count > 0) return responseOld.Users[0].Id; // The user is not previously registered with zen. Lets register now. ZendeskApi_v2.Models.Users.User zenUser = new ZendeskApi_v2.Models.Users.User(); zenUser.Active = true; zenUser.Alias = user.DisplayName; zenUser.Details = type; //zenUser.Photo = new ZendeskApi_v2.Models.Users.Photo { ContentUrl = user.Photo }; zenUser.Email = user.Credential.Email; zenUser.Name = user.DisplayName; zenUser.ExternalId = user.UserId; zenUser.Verified = true; zenUser.Role = type.Trim().ToLower(); ZendeskApi_v2.Models.Users.IndividualUserResponse response = api.Users.CreateUser(zenUser); if (response.User == null) return null; return response.User.Id; }
private static ZendeskApi GetApi() { var useSettings = false; var settings = Settings.Default; // Load setings? { Console.WriteLine("Use settings? Y/N"); if (Console.ReadLine().ToLower() == "y") { useSettings = true; settings.Upgrade(); } } String path, email, password; Func<String, Boolean> isNeedInput = field => !useSettings || String.IsNullOrEmpty(field); // Path { path = settings.Path; if (isNeedInput(path)) { Console.WriteLine("Enter Path"); path = Console.ReadLine(); settings.Path = path; } else { Console.WriteLine("Path: " + path); } } // EMail { email = settings.EMail; if (isNeedInput(email)) { Console.WriteLine("Enter EMail"); email = Console.ReadLine(); settings.EMail = email; } else { Console.WriteLine("Email: " + email); } } // Password { password = settings.Password; if (isNeedInput(password)) { Console.WriteLine("Enter Password"); password = Console.ReadLine(); settings.Password = password; } else { Console.WriteLine("Password: "******"/api/v2", email, password); try { Console.WriteLine("Connecting..."); CurrentUser = api.Users.GetCurrentUser().User; Console.WriteLine("Hello {0}", CurrentUser.Name); //if (useSettings) { // save to C:\Users\<UserName>\AppData\Local\ZendeskPrototype\ settings.Save(); } } catch (Exception exception) { Console.WriteLine(exception.Message); } return api; }