I have a need to dynamically disable/enable extensions using the API in PHP?
I have been using the API for years using it to change an extensions caller id and name and redirecting calls but i am unable to find a way to disable/enable extensions.
my thoughts were to simply change the password of the extension but i have not been successful in doing so while using the API.
Asterisk itself using AMI does not provide a way to enable or disable extensions. What you’ve done there is update some FreePBX specific Asterisk database entry to update the callerid. I doubt there’s any database entries you could change to enable or disable extensions.
It’s updating a database entry that FreePBX created and uses in the Asterisk database, it’s not updating Asterisk itself. Asterisk doesn’t itself use that database entry. Only the logic that FreePBX has in place does.
It is entirely possible that you are not running FreePBX. However, for that code to function to modify the extension settings, it must be using dialplan (extensions.conf) that was either modelled after or borrowed from FreePBX. The AMPUSER key is what FreePBX uses to modify extension settings in the AstDB.
To provide the enable/disable function you desire, you will likely need to adjust the dialplan further to check an additional activation flag. There may be other ways of accomplishing what you want as well. However, what you seek to do is not an integral feature provided by Asterisk, short of rewriting the sip or pjsip configuration files to remove an endpoint.
thanks for the feedback. Its odd that the code works as we have been using it on a machine that never had FreePBX installed. that said I need to double check a few things then. Much appreciated!
I should then ask if you know a way via the AMI API to set an extensions outbound caller ID without using the AMPUSER key? I know how to change the caller id on an active channel as we currently do this prior to redirecting a channel. Again, your help is really appreciated.
On a side note, did you see where I asked about changing the extension password using the AMI API? this would effectively disable the extension. The only method I see now, but have not tested, is possibly using the UpdateConfig Action.
When you say extension password, what specific concept in Asterisk - not FreePBX - are you referring to?
An Asterisk extension has no concept of a ‘password’. You may implement such a concept using certain dialplan applications, but it is not an intrinsic part of Asterisk.
No it is the device authentication password. There are no Asterisk extensions in sip.conf. (JColp has silently compensated for your use of FreePBX terminology.)
Hello, I am working with the API Action UpdateConfig which will allow me to directly update an asterisk conf file. This should allow me to dynamically make the changes that I need but am not finding success as with the following code I am getting a “Message: Save of config failed”. If anyone can review the following code to see if they can suggest what may be the issue it would be greatly appreciated. Thank you all in advance.