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. http://finesse.company.com
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))
print(res.status_code)

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))
print(res.status_code)
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)

~david

Leave a Reply