I have a script that updates contacts information in InfusionSoft via the REST API. Everything works perfectly except for the addresses.
I’ll include how I update email and addresses since email works but address does not even though they should work in the same way.
elif value == 'email':
fields_to_update['email_addresses'] = contact['email_addresses']
for email in fields_to_update['email_addresses']:
if email['field'] == "EMAIL1":
email['email'] = updated_values['email']
elif value == 'billing_address_line_1':
fields_to_update['addresses'] = contact['addresses']
for address in fields_to_update['addresses']:
if address['field'] == "BILLING":
address['line1'] = updated_values['billing_address_line_1']
With these two functions I create an “updated_fields” object and send it like this.
new_contact = update_infusionsoft_primary_sandbox_contact_data(current_contact, updated_fields)
patch_parameters = {"access_token": current_company_access_token}
request_url = "https://api.infusionsoft.com/crm/rest/v1/contacts/" + str(current_contact['id'])
headers = {'content-type': 'application/json'}
contact_update = requests.patch(request_url, json=new_contact, params=patch_parameters, headers=headers)
For some reason email works. It grabs all of the emails as they are and changes just the field that has changed. The addresses should work the same way but for some reason when address is included I get a 400 response and it doesn’t update any of the fields.
Here is what I am currently passing in that is failing.
{'email_addresses': [{'email': 'apu9@kwikimart.com', 'field': 'EMAIL1'}], 'addresses': [{'line1': '106 Street Lane', 'line2': 'Apt 1', 'locality': 'Denver', 'region': 'Co', 'field': 'BILLING', 'postal_code': '12345', 'zip_code': '12345', 'zip_four': '', 'country_code': 'USA'}, {'line1': '400 Clearbrooke Terrace', 'line2': '', 'locality': 'Cottage Grove', 'region': 'Wi', 'field': 'SHIPPING', 'postal_code': '53527', 'zip_code': '53527', 'zip_four': '', 'country_code': 'USA'}]}