3CX API with PowerShell

Discussion in '3CX Phone System - General' started by Togadude, Jun 8, 2018.

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

    Joined:
    Jun 5, 2018
    Messages:
    11
    Likes Received:
    4
    Hi all,

    Anyone successfully using the 3CX Call Control API with PowerShell?
    I've found some useful code on the forum, but I can't get it to work.

    Config: 3CX Enterprise 15.5 on Windows 2016 Enterprise with PowerShell 5.1

    The error I get is like this:
    upload_2018-6-8_9-5-7.png

    Thanks!
    T.
     
  2. Togadude

    Joined:
    Jun 5, 2018
    Messages:
    11
    Likes Received:
    4
    No takers yet?

    I got some better results with calling the DLL with 'Add-Type' instead of 'System.Reflection.Assembly' using the following code:
    Code:
    Add-Type -Path "C:\Program Files\3CX Phone System\Instance1\Bin\3cxpscomcpp2.dll"
    Requesting the properties like so:
    Code:
    [TCX.Configuration.PhoneSystem].GetProperties()
    returns the attributes, so on to connecting...
    upload_2018-6-11_9-13-47.png

    Code:
    [TCX.Configuration.PhoneSystem]::set_CfgServerHost("127.0.0.1")
    [TCX.Configuration.PhoneSystem]::set_CfgServerPort("5485")
    [TCX.Configuration.PhoneSystem]::set_CfgServerUser("cfguser_default")
    [TCX.Configuration.PhoneSystem]::set_CfgServerPassword("******")
    [TCX.Configuration.PhoneSystem]::set_ApplicationName("CallViewer")
    
    upload_2018-6-11_9-23-45.png

    All looking good.

    However, when trying to instantiate an object like so:
    Code:
    $3CX = [TCX.Configuration.PhoneSystem]::get_Root()
    it throws a "ConfigServer is not connected" right back at me...
    upload_2018-6-11_9-27-54.png

    Hopefully ringing any bells now?

    Thanks!
    T.
     
    LtFrankDrebin and HLM 3CX like this.
  3. Togadude

    Joined:
    Jun 5, 2018
    Messages:
    11
    Likes Received:
    4
    Making progress, succeeded in connecting.
    Even managed to load extension data in an object like this:
    Code:
    $Ext = $Tenant[0].GetExtensions() | where ID -eq 390
    The following changes the last name of the user (instantly!)
    Code:
    $Ext.Lastname = "Doe"
    $Ext.Save
    However, the following code does nothing :(
    Code:
    $Ext.UserStatus = "Away"
    $Ext.Save
    Still plowing away...
    T.
     
    craigreilly and HLM 3CX like this.
  4. HLM 3CX

    Joined:
    Feb 26, 2018
    Messages:
    8
    Likes Received:
    0
    Nice!

    Did you get farther along in it?

    Thank you!
     
  5. NickD_3CX

    NickD_3CX Support Team
    Staff Member 3CX Support

    Joined:
    Jun 2, 2014
    Messages:
    1,368
    Likes Received:
    84
    I have no experience with running code from PowerShell, but a little experience with Visual Studio.

    I don't know if this helps, but "UserStatus" does not accept a string as a value, but objects of type "UserStatusType" which is an enum class. Try assigning an int instead of a string, and I think the only 2 values are 0 = Available, 1 = Away.

    No much more I can pitch in though....
     
  6. Danny Lauwers

    Joined:
    Aug 30, 2017
    Messages:
    2
    Likes Received:
    0
    Hi,

    suddenly last night, we got this error:

    2018-06-14 17:43:43,513 [4] INFO _3cxSync.PBX3cxConnector [(null)] - phonesystem.root connected voor aanvraag GETDN
    2018-06-14 17:43:48,731 [4] ERROR _3cxSync.PBX3cxConnector [(null)] - TCX.Configuration.Exceptions.PhoneSystemException: ConfigServer is not connected
    at TCX.Configuration.PhoneSystem.Connect()
    at TCX.Configuration.PhoneSystem.get_Root()
    at _3cxSync.PBX3cxConnector.Initialize(String applicationName, String version) in C:\Projects\WPF\Domus Admin\DaMainServicePlugin\3cxSync\PBX3cxConnector.cs:line 82
    2018-06-14 17:43:49,160 [4] INFO _3CXSyncService.Sync [(null)] - ConfigServer is not connected


    Had been working perfectly ?

    User/password are correct.

    Could it be that there was a 3CX/windows update that causes this ?

    Any idea on how to resolve this error ?

    Hope you can help !
    Danny
     
  7. LtFrankDrebin

    Joined:
    Mar 17, 2018
    Messages:
    16
    Likes Received:
    1
    Hey Togadude,

    just stumpled upon your post because i am trying to set up some routines started from powershell.
    What can i say, you already assumed, it does not work for me.
    I actually am only trying to get a sample running which makes a new phone book entry.

    Do you have a simple (complete w/o passwords) example of how you get your code running?

    Thank you very much for your efforts!
    Andreas
     
Thread Status:
Not open for further replies.