.NET API and Provisioning

Discussion in '3CX Phone System - General' started by tonvdp, Apr 7, 2009.

Thread Status:
Not open for further replies.
  1. tonvdp

    Joined:
    Apr 7, 2009
    Messages:
    2
    Likes Received:
    0
    Hello,

    I have downloaded the sample .net API, and got the code to work (once I figured out how to connect to the 3CS server...).

    I can now query the available information in the PBX, but I am looking for a way to, programattically, add members to huntgroups, create huntgroups, create digital assistents etc. I think that maybe the lack of documentation is what's getting to me, but could someone point me in the right direction here?

    For reference, I have added the following code to the sample program:
    Code:
                    TCX.Configuration.PhoneSystem.Root.Host = "127.0.0.1";
                    TCX.Configuration.PhoneSystem.Root.Port = 5485;
                    TCX.Configuration.PhoneSystem.Root.Username = "admin";
                    TCX.Configuration.PhoneSystem.Root.Password = "*****";
                    TCX.Configuration.PhoneSystem.Root.Connect();
    I can get at the information okay, with code like the following:
    Code:
                TCX.Configuration.RingGroup[] theGroups;
                theGroups = TCX.Configuration.PhoneSystem.Root.GetRingGroups();
                MessageBox.Show(theGroups[0].Name);
                MessageBox.Show(theGroups[0].Members[0].Number);
    Hope you can help,

    Best regards,

    //Ton
     
  2. magoo

    Joined:
    Apr 6, 2009
    Messages:
    13
    Likes Received:
    0
    Hi Tonvdp, I personally have not looked at this in any great detail YET!, but the subject does interest me and perhaps someone digging around with you into this topic, may help. Personally, I am a total Newbie to 3CX PBX, but feel I have to jump in to see if I can help (and learn) because this topic is of such interest to me too.

    If your successful in your project, it would be great if you could re-post here with your results, feedback, comments and suggestions, so the rest of us with an interest may explore this topic even further, in the mean time...

    I believe that the 3CX PBX application sits on top of a PostgreSQL Database and there is currently only a limited database view of this underlying schema using ODBC and the 'logreader' username and password connection string.

    ( see http://docs.google.com/View?docid=dqnz5cc_59cb9jn8hp for more details )

    I am assuming that what would be required to carry out such a task, would be full access to the entire database and its underlying tables in order to be able to add or modify the configuration of 3CX PBX.

    I have not yet tried any of this YET!, but I would imagine tools like the following:

    ( http://sqlmanager.net/en/products/postgresql/manager/download )

    Should be a good starting position and allow (given the correct database registration details) a developer to manually populate and modify the related records as required where you need to first discover and test you way about.

    Once this provisional discovery and testing is out of the way, your back to a .net ADO.net data provider for full on application integration and deployment.

    I hope I am addressing your query directly because correctly I am not 100% sure that I have understood your question correctly.

    All the above makes to major assumptions:
    1. You have a full and complete backup of everything before your start
    2. 3CX licensing, copyright and intellectual property rights allows for such an approach
    3. This is the question you are asking

    In any case, could I suggest you build a sample (proof of concept) .net project ( VS2008 VB.net if possible ) and lets all have a look ...

    just my 2 cents ...
     
  3. tonvdp

    Joined:
    Apr 7, 2009
    Messages:
    2
    Likes Received:
    0
    Well,

    I have partially solved my own questions... I am now able to:
    - Create an Extension
    - Add a RingGroup
    - Add the newly created extension to the ringgroup
    - Delete the ringgroup
    - Delete the extension

    But have some problems to set forwarding-rules on the extension.... Maybe someone has some ideas for that?

    Anyway, here's some code to add the stuff:
    Code:
                TCX.Configuration.Tenant theTenant;
                theTenant = TCX.Configuration.PhoneSystem.Root.GetTenants()[0];
    
                // Add Extension
                TCX.Configuration.Extension myExt = theTenant.CreateExtension("204");
                myExt.FirstName = "Computer";
                myExt.Save();
    
                // Add RingGroup
                TCX.Configuration.RingGroup myGroup;
                myGroup = theTenant.CreateRingGroup();
                myGroup.Name = "computer-created";
                myGroup.Number = "899";
                myGroup.Save();
    
                // Add member to RingGroup
                TCX.Configuration.DN[] theMembers;
                theMembers = myGroup.Members;
                Array.Resize(ref theMembers, theMembers.Length + 1);
                theMembers[theMembers.Length - 1] = myExt;
                myGroup.Members = theMembers;
                myGroup.Save();
    
                theTenant.Save();
    And here's the code I use to delete the stuff...

    Code:
                TCX.Configuration.Tenant theTenant;
                theTenant = TCX.Configuration.PhoneSystem.Root.GetTenants()[0];
    
                // Delete Extension
                TCX.Configuration.Extension[] myExts = theTenant.GetExtensions();
                foreach (TCX.Configuration.Extension anExt in myExts)
                {
                    if (anExt.Number.Equals("204"))
                    {
                        anExt.Delete();
                        //anExt.Save();
                    }
                }
    
                // Delete RingGroup
                TCX.Configuration.RingGroup[] myGroups = theTenant.GetRingGroups();
                foreach (TCX.Configuration.RingGroup anGroup in myGroups)
                {
                    if (anGroup.Number.Equals("899"))
                    {
                        anGroup.Delete();
                        //anGroup.Save();
                    }
                }
    
                theTenant.Save();
    And here's the code I have problems with...

    Code:
                TCX.Configuration.Tenant theTenant;
                theTenant = TCX.Configuration.PhoneSystem.Root.GetTenants()[0];
    
                // Delete Extension
                TCX.Configuration.Extension[] myExts = theTenant.GetExtensions();
                foreach (TCX.Configuration.Extension anExt in myExts)
                {
                    if (anExt.Number.Equals("101"))
                    {
                        TCX.Configuration.ExtensionRule myRule = anExt.CreateForwardingRule();
                        myRule.Forward.To = TCX.Configuration.DestinationType.External;
                        myRule.Forward.External = "+3162312345";
                        TCX.Configuration.HoursRange myRange = myRule.CreateHoursRange();
                        myRange.StartTime = DateTime.Now;
                        myRange.EndTime = DateTime.Now.AddMonths(12);
                        anExt.Save();
                        //anExt.Save();
                    }
                }
     
  4. JohnGrenfell

    Joined:
    May 18, 2010
    Messages:
    6
    Likes Received:
    0
    Hi,

    I'm hoping to do a similar in PowerShell with .Net. When I try and connect I get the error

    “Exception calling "Connect" with "0" argument(s): "Config server is not connected"”


    The TCX.Configuration.PhoneSystem object looks like this

    Connected : False
    ConfigVersion : 10.0.22052.2264
    Build : 2264
    Version : 10.0.22052.2264
    Password : *****
    Username : admin
    Database : phonesystem
    Port : 5485
    Host : 127.0.0.1

    Any ideas?

    Thanks,

    John
     
  5. SY

    SY Well-Known Member
    3CX Support

    Joined:
    Jan 26, 2007
    Messages:
    1,825
    Likes Received:
    2
    Hi John,

    Could you please post the PS (Powershell) script?
    Most probably you have overlooked obvious things.
    Thanks
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  6. JohnGrenfell

    Joined:
    May 18, 2010
    Messages:
    6
    Likes Received:
    0
    Hi Stepan,

    Thanks for getting back to me. I think I've just cracked it, I changed the ApplicationName from CFGManager to CallViewer via [TCX.Configuration.PhoneSystem]::set_ApplicationName

    I'll let you know how I get on as I'm currently only reading information. I may wish to update the email address of some extension details and I'm guessing "CallViewer" can't do this?

    Thanks again,

    John
     
  7. JohnGrenfell

    Joined:
    May 18, 2010
    Messages:
    6
    Likes Received:
    0
    Hi,

    I'm happy with the numerous get methods and can update extension details which is great. :D (is there a way of updaing group membership?)

    I'm struggling to find a method to retrieve all the Phones with IP/Mac, is this something I need to programmatically build out of the GetExtensions method?



    Thanks,

    John
     
Thread Status:
Not open for further replies.