How to get OTRS agents list from .NET application

Unfortunately, I coudn’t find OTRS web service method to reterieve list of OTRS agents: user name and IDs. I create forum topics on the official forum to solve the task.

I found some workaround. It’s not so fast as I would like, but it fast enough (takes several seconds) to retrieve list of OTRS users with user ID via web service. Such information is extremely important to use OTRS TicketSearch method, since it use only Responsible ID as a property. Here is C# code example:

        private OTRS.ServiceReference.GenericTicketConnector_InterfaceClient _otrs = null;
        public OTRS.ServiceReference.GenericTicketConnector_InterfaceClient OTRS
        {
            get
            {
                if (_otrs == null)
                {
                    _otrs = new OTRS.ServiceReference.GenericTicketConnector_InterfaceClient("GenericTicketConnector_endPoint");
                    if (_otrs != null)
                    {
                        //otrs.ClientCredentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials;
                        //_otrs.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation; //Very IMPORTANT when NTLM auth
                    }
                }
                return _otrs;
            }
        }

        private OTRS.ServiceReference.OTRS_SessionCreateResponse _Session = null;
        public OTRS.ServiceReference.OTRS_SessionCreateResponse Session
        {
            get
            {
                if (OTRS != null)
                {
                    OTRS.ServiceReference.OTRS_SessionCreate sc = new OTRS.ServiceReference.OTRS_SessionCreate();
                    sc.ItemElementName = ItemChoiceType8.UserLogin;
                    sc.Item = tbUserName.Text;
                    sc.Password = tbPassword.Text;
                    _Session = OTRS.SessionCreate(sc);
                }
                return _Session;
            }
        }

        public async void GetUserAsync()
        {
            if (OTRS != null)
            {
                OTRS.ServiceReference.OTRS_TicketSearch ticketSearch = new OTRS.ServiceReference.OTRS_TicketSearch();
                ticketSearch.ItemElementName = ItemChoiceType6.SessionID;
                ticketSearch.Item = Session.SessionID;

                lvAgents.Items.Clear();
                for (int i = 0; i <= 1000; i++) //
                {
                    ticketSearch.ResponsibleIDs = new string[] { i.ToString() };

                    TicketSearchResponse x = await OTRS.TicketSearchAsync(ticketSearch);

                    if (x.TicketSearchResponse1 != null && x.TicketSearchResponse1.Length > 0)
                    {
                        if (OTRS != null)
                        {
                            OTRS.ServiceReference.OTRS_TicketGet ticketGet = new OTRS.ServiceReference.OTRS_TicketGet();
                            ticketGet.ItemElementName = ItemChoiceType5.SessionID;
                            ticketGet.Item = Session.SessionID;

                            ticketGet.TicketID = new string[] { x.TicketSearchResponse1[0] };
                            ticketGet.AllArticles = "0";
                            ticketGet.Attachments = "0";

                            TicketGetResponse tickets = await OTRS.TicketGetAsync(ticketGet);
                            if (tickets != null && tickets.TicketGetResponse1.Length > 0)
                            {
                                foreach (OTRS.ServiceReference.OTRS_TicketGetResponse_Ticket ticket in tickets.TicketGetResponse1)
                                {
                                    if (!string.IsNullOrEmpty(ticket.ResponsibleID))
                                    {
                                        ListViewItem lvi = lvAgents.Items.Add(ticket.ResponsibleID);
                                        lvi.SubItems.Add(ticket.Responsible);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Опубликовать в Facebook
Опубликовать в Google Plus
Опубликовать в LiveJournal
Опубликовать в Мой Мир
Опубликовать в Одноклассники
Опубликовать в Яндекс
Запись опубликована в рубрике IT tools с метками , , , , . Добавьте в закладки постоянную ссылку.