HealthITAU / pyconnectwise

A library for simplifying interactions with the ConnectWise Manage API in Python
https://healthit.com.au
GNU General Public License v3.0
42 stars 7 forks source link

I can't figure out how to update a contact #27

Open pdath opened 1 month ago

pdath commented 1 month ago

I'm trying to update a phone number in a contact (actually lots and lots of contacts). I start out going:

paginated_contacts = manage_api_client.company.contacts.paginated(1,00) for contact in paginated_contacts.all(): ... contact.default_phone_nbr="xxx"

How do I post that update? manage_api_client.company.contacts.post(contact) contact.post() I can't seem to guess the syntax.

pdath commented 1 month ago

For anyone finding this in the future I finally figured it out. Basically to update a field (like phone number) you do something like:

paginated_contacts = manage_api_client.company.contacts.paginated(1,00) for contact in paginated_contacts.all():

Skip records with no contact info at all

if(contact.communication_items) is None:
    continue;

for communication in contact.communication_items:
    # Only process contact phone numbers
    if(not(communication.type.name=="Direct" or communication.type.name=="Mobile" or communication.type.name=="Home")):
        continue;

    payload = [{"op": "replace", "path": "value", "value": "+1(813)0005555"}]
    manage_api_client.company.contacts.id(contact.id).communications.id(communication.id).patch(payload)