Cisco CUCM Extension Mobility Api Python3 – Remote Login

By 7th March 2018Cisco, CUCM, EMAPI

When rolling out extension mobility to large numbers of users, one of your decisions will be whether to log users in prior to go live. Personally I think this helps to enable a smoother transition.
The following example uses the Cisco CUCM extension mobility Api, you can achieve the same using the AXL api in this example.


__author__ = "Mitch Dawson"
__contact__ = ""
__copyright__ = "Copyright (C) 2017 - 2018 Ucdevops All Rights Reserved"
__license__ = "GPLv3"

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see

# Import the requests http library
import requests

# Define our request headers
header = {
    "Content-Type": "application/x-www-form-urlencoded"

# Define our individual cucm extension mobility hosts
host = "https://cucm1"

# Define our extension mobility api url
em_url = ":8443/emservice/EMServiceServlet"

# Define our extension mobility proxy user credentials
# The accouunt needs the "Standard EM Authentication Proxy Rights" role applied
proxy_user = "username"
proxy_pass = "password"

# Define our Login class
class Login:

    def __init__(self, url, proxy_user, proxy_password):
        self.url = url
        self.proxy_user = proxy_user
        self.proxy_pass = proxy_password

    def login_msg(self, mac, profile, uid):
        # The function creates our message, required to perform a login request
        # Takes the Phone MAC, Device Profile Name and userid as input
        return """
        """.format(self.proxy_user, self.proxy_pass, mac, uid, profile)

    def make_request(self, message):
        # The function posts our message to Extension Mobility API
            data={"xml": message},

    def do_login(self, mac, profile, uid):
        # Function which carries out our required steps to perform our login
        print("*" * 50, "\n")
            "Logging in User '{}' into Handset {} "
            "with Profile {} .....\n"
            .format(uid, mac, profile)
                self.login_msg(mac, profile, uid)
        print("*" * 50, "\n")

def main():

    # Open and read our csv input file
    data = open("login.csv", "r").read().split("\n")

    # Instantiate our "Login" class
    login = Login(
        host + em_url, proxy_user, proxy_pass

    # Loop through our login data, skipping our header line
    for line in data[1:]:
        mac, profile, uid = line.split(",")
        login.do_login(mac, profile, uid)

if __name__ == "__main__":

Logging in User Mitch.Dawson into Handset SEP40A6E8B05B65 with Profile UDP_8205702_8861 .....
<?xml version="1.0"?>


Author Mitch

I am an independent IT Consultant with specialities in Software Development, Enterprise Unified Communication, Network and Security platforms. In addition to my day to day work, I develop bespoke applications and I hope that through I can build relationships with clients, business partners and fellow engineers by providing solutions to complex problems through the use of programming.

More posts by Mitch

Leave a Reply