Find specific phone number in Finesse phone books through the Finesse API using Python

Here’s a quick Python script that will allow you to go through each phone book in Finesse and identify the phone book that has the phone number(s) you’re after. Just fill in your information ‘<>’ and update the numbers you want to find.

import requests # for using API
from requests.auth import HTTPBasicAuth
import xml.etree.ElementTree as ET # for parsing XML

requests.packages.urllib3.disable_warnings() #If using a self signed certificate

rootURL = ‘<>’ # e.g.
phonebooksURL = ‘/finesse/api/PhoneBooks’
username = ‘<>’ #Finesse admin username
password = ‘<>’

headers = {‘Accept’: ‘application/xml’, ‘Content-Type’: “application/xml”}

phonenumbers = [‘5555551234’, ‘5555551235’, ‘5555551236’, ‘5555551237’] #phone numbers you want to find.

res = requests.get(rootURL+phonebooksURL, headers= headers, verify=False, auth=HTTPBasicAuth(username, password))

root = ET.fromstring(res.content)

for phonebooks in root:
phonebookId = phonebooks[3].text
res = requests.get(rootURL+phonebookId+’/Contacts’, headers=headers, verify=False, auth=HTTPBasicAuth(username, password))
root = ET.fromstring(res.content)
for contacts in root:
for number in phonenumbers:
if number in contacts[3].text:
print(phonebooks[2].text, contacts[3].text)


Finesse Error: The device associated with that extension or dial number is invalid.

This is the first time I’ve used an 8945 phone as an agent phone and while the documentation states it’s supported, I kept getting the above error which made no sense to me as everything looked right. Checked out the jtapi logs and this is what it said:

16:48:24:420 PG1A-jgw1 Trace: MsgAddCallObserver:  Addr: 7778 Remote Addr: 0 InvID: 8380 CallDeliveryMode ID: 0.
16:48:24:420 PG1A-jgw1 Trace: Adding Call Observer to: 7778.
16:48:24:420 PG1A-jgw1 Trace: Address Name: 7778IP Addressing Mode:IP_ADDRESSING_MODE_IPV4.
16:48:24:420 PG1A-jgw1 Trace: AddCallObserver address validation failed – Address Name: 7778, error code: 154.
16:48:24:420 PG1A-jgw1 Trace:   MsgAddCallObserverResponse:  Addr: 7778 Succeeded: 0 InvID: 8380 Cause: 154.

Which then let me to this link. The problem was something I’ve never had to set in the UCM before. Join And Direct Transfer Policy.


Once that was changed the the phone recycled, everything worked. Go figure.