Searching contacts using Python 3.9.1

Hi all. I want to import invoices into FA from a csv file. The first step is to download the contacts using the code below (that I have adapted from another post on here) which works, I get a list of contacts from the sandbox API.

Sample code

The second step is to check the list of contacts so I can create a new contact for a new invoice if required. How do I save the downloaded json as a Python dictionary? I get this error when I try to use the downloaded variable/object.

    print('Walter' in response)

TypeError: argument of type ‘FreeAgentResponse’ is not iterable

Thanks in advance, I’m not a programmer but can stumble my way around Python with a bit of help.

EDIT: I’ve discovered that the class FreeAgentResponse is the problem. I need to convert the output to a dictionary but am struggling with the best way to do this.

Solved using the vars() function as shown below.

def contactList(contact):   #List of contacts in FA
clist = []
contact = vars(contact)
contact = contact['response']
contact = contact['contacts']
for contacts in contact:
1 Like