cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2473
Views
5
Helpful
8
Replies

python AXL cucm update phone with line Failed....

hi

i have phone name = 

SEP00059A3C7Acc

 

with:

line1 = 111 , line 2 = 555 , line3 = 666

 

 

when i make update phone they remove line2 and line3 and update line1

 

from zeep import Client
from zeep.cache import SqliteCache
from zeep.transports import Transport
from zeep.plugins import HistoryPlugin
from requests import Session
from requests.auth import HTTPBasicAuth

# CUCM HostName/ IP Address
host = '192.168.1.30'
# WSDL Service location download AXLToolKit from Call Manager
wsdl = 'AXLAPI.wsdl'
# UserName and Password
user = 'admin'
pwd = 'password'
location = 'https://{host}:8443/axl/'.format(host=host)
binding = "{http://www.cisco.com/AXLAPIService/}AXLAPIBinding"
session = Session()
session.verify = False
session.auth = HTTPBasicAuth(user, pwd)
transport = Transport(cache=SqliteCache(), session=session, timeout=20)
history = HistoryPlugin()
client = Client(wsdl=wsdl, transport=transport, plugins=[history])
service = client.create_service(binding, location)



def update_Phone():
try:
response = service.updatePhone(name="SEP00059A3C7Acc",
lines={"line" : {"index": 1,
"dirn": {"pattern": "111",
"routePartitionName": "A"}
}
}

)


print(response)

except Exception as e:
print(str(e))



update_Phone()

how to fix this problem..

8 Replies 8

derek.fraser
Level 1
Level 1

I ran into a similar scenario, check out this thread for a more detailed description of the problem.  It's not that you're doing anything incorrectly, but more understanding how the API functions.

 

https://community.cisco.com/t5/management/axl-update-device-profile-line-appearance/m-p/4062936#M3374 

Adam Pawlowski
VIP Alumni
VIP Alumni
List items like lines, speed dial, blf speed dial, etc have to be ALL written back with the call otherwise they fall off.

The API rarely is actually "updating" anything but usually rather replacing.

I call getPhone first, to get the associated line appearances, then you can unpack that as either a hash or array of hashes, modify the values you want, and put the whole thing back with an update call. You're going to want to do this with most of the attributes to avoid losing them. The only one that I haven't figured out how to get past is the load information, since AXL ships out what it should be, default or otherwise, and you have no way to know if it's been set manually. If you write that one back then it will fill in the field even if it was empty before.

npetrele
Cisco Employee
Cisco Employee

You're only defining one line, so when it updates the phone, is assumes you only want one line. You need to do the python/json equivalent of the following XML, which would define 2 lines.

 

      <lines>
        <line>
          <index>1</index>
          <dirn>
            <pattern>1001</pattern>
            <routePartitionName>Internal-PT</routePartitionName>
          </dirn>
        </line>
        <line> 
<index>2</index>
<dirn>
<pattern>1002</pattern>
<routePartitionName>Internal-PT</routePartitionName>
</dirn>
</line>
</lines>

The equivalent to the xml that would define 2 lines is a list.  When I use that list together with update_phone all of the lines are removed.  The xml looks like

<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
<soap-env:Body>
<ns0:updatePhone xmlns:ns0="http://www.cisco.com/AXL/API/12.5">
<name>SEPF04A02EEED5B</name>
<description>Test axl description</description>
<lines/>
</ns0:updatePhone>
</soap-env:Body>
</soap-env:Envelope>

 

Yes if you do that it will remove the lines, as you're supplying an empty list element for lines with nothing in it.

 

The next time I wrote this function into a project I decided to not go down that road and instead use addLine for adding a line. You can do it with update phone. I did learn a lesson however that there have been bugs in the past about sending in empty tags and parsing, and I try not to do that. I thought it would be "cool" to getPhone, update what I want, and paste it back with updatePhone until I broke things. (<vendorConfig />).

Loosely, with addPhone:

                line_data = {
                    'line': {
                        'index': new_index,
                        'display': display_name,
                        'displayAscii': display_name,
                        'label': line['line']['alertingName'][:30],
                        'dirn': {
                            'pattern': line['line']['pattern'],
                            'routePartitionName': line['line']['routePartitionName']['_value_1']
                        },
                        'e164Mask': '716XXXXXXX',
                        'associatedEndusers': {
                            'enduser': {
                                'userId': user_id
                            }
                        },
                        'callInfoDisplay': {
                            'callerName': 't',
                            'callerNumber': 'f',
                            'redirectedNumber': 'f',
                            'dialedNumber': 't'
                        },
#                        'maxNumCalls': '2',
#                        'busyTrigger': '2'
                    }
                }

                # Update device

                params = {
                    'name': csf_device,
                    'addLines': line_data
                }

                try:

                    result = VoIPXMPPBot.axl_client.service_proxy.updatePhone(**params)

I am using the serviceProxy to re-write the endpoint, but however else you're addressing it, that format works. Display Name values are shortened elsewhere in my code and not there, same with scrubbing out characters like '&' that otherwise cause fault.

 

 

Adam,

If I am understanding you correctly you did an update phone with no lines and did an add line afterwards?

I have python code that updates the line for a phone that has only one line and produces this correct result.  It does not work for 2 or more lines.

 

One line Request

-------

Headers:

{'SOAPAction': '"CUCM:DB ver=12.5 updatePhone"', 'Content-Type': 'text/xml; charset=utf-8'}

 

Body:

<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">

  <soap-env:Body>

    <ns0:updatePhone xmlns:ns0="http://www.cisco.com/AXL/API/12.5">

      <name>SEPF04A02EEED5B</name>

      <description>Test axl description</description>

      <lines>

        <line>

          <index>1</index>

          <display>P Test - Display</display>

          <dirn>

            <pattern>\+18133920819</pattern>

            <routePartitionName>INTERNAL-PT</routePartitionName>

          </dirn>

          <displayAscii>P Test - DisplayA</displayAscii>

        </line>

      </lines>

    </ns0:updatePhone>

  </soap-env:Body>

</soap-env:Envelope>


@mserwon wrote:

Adam,

If I am understanding you correctly you did an update phone with no lines and did an add line afterwards?

I have python code that updates the line for a phone that has only one line and produces this correct result.  It does not work for 2 or more lines.

 


Yes, you can do that, but if you send back <lines /> then it will remove all the lines from the device, so whatever was formatting that XML didn't give you what you wanted.  Looks like you got your problem resolved - perhaps there was an issue with the serialization that was happening before.

Add line works fine if you want to process it that way without playing with the other elements, so you could say, coke up some sort of thing like a "Night Mode" script that takes a line that would be at reception/service and adds it to other manned devices, and one that removes it, for coverage at a store or utility plant for example. It would be based on device list and known layout of the device.

I was able to use python ordered dictionaries and zeep to get the xml correct to update more than one line.

 

cucm_resp = ucm.update_phone(name=dfaxl['name'][idx],
description=dfaxl['description'][idx],
lines = linedict3)

 

linedict3 = OrderedDict([
('line',
[([OrderedDict([('index', 1),
('label', 'P1 Test - Label'),
('display', 'P1 Test - Display'),
('displayAscii', 'P1 Test - Display A'),
('dirn', OrderedDict([('pattern', '\\+18133920819'), ('routePartitionName', 'INTERNAL-PT' )]))
])]),
([OrderedDict([('index', 2),
('label', 'P1 Test - Label2'),
('display', 'P1 Test - Display2'),
('displayAscii', 'P1 Test - Display2 A'),
('dirn', OrderedDict([('pattern', '\\+18133919999'), ('routePartitionName', 'INTERNAL-PT' )]))
])])]
)])

 

Here is the debug output

 

Request
-------
Headers:
{'SOAPAction': '"CUCM:DB ver=12.5 updatePhone"', 'Content-Type': 'text/xml; charset=utf-8'}

Body:
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
<soap-env:Body>
<ns0:updatePhone xmlns:ns0="http://www.cisco.com/AXL/API/12.5">
<name>SEPF04A02EEED5B</name>
<description>P Test Good</description>
<lines>
<line>
<index>1</index>
<label>P1 Test - Label</label>
<display>P1 Test - Display</display>
<dirn>
<pattern>\+18133920819</pattern>
<routePartitionName>INTERNAL-PT</routePartitionName>
</dirn>
<displayAscii>P1 Test - Display A</displayAscii>
</line>
<line>
<index>2</index>
<label>P1 Test - Label2</label>
<display>P1 Test - Display2</display>
<dirn>
<pattern>\+18133919999</pattern>
<routePartitionName>INTERNAL-PT</routePartitionName>
</dirn>
<displayAscii>P1 Test - Display2 A</displayAscii>
</line>
</lines>
</ns0:updatePhone>
</soap-env:Body>
</soap-env:Envelope>


Response
-------
Headers:
{'X-Frame-Options': 'SAMEORIGIN', 'Strict-Transport-Security': 'max-age=31536000; includeSubdomains', 'Content-Security-Policy': "default-src *; script-src * 'unsafe-inline' 'unsafe-eval';style-src * 'unsafe-inline'; img-src * data: 'unsafe-inline';", 'X-Content-Type-Options': 'nosniff', 'X-XSS-Protection': '1; mode=block', 'Content-Type': 'text/xml;charset=UTF-8', 'Content-Length': '311', 'Date': 'Sat, 08 Jan
2022 02:47:26 GMT', 'Server': ''}

Body:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ns:updatePhoneResponse xmlns:ns="http://www.cisco.com/AXL/API/12.5">
<return>{7AA8E651-DA96-A210-E922-5CD9DD416664}</return>
</ns:updatePhoneResponse>
</soapenv:Body>
</soapenv:Envelope>

 

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: