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': '[email protected]', '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'}]}
You need to use ISO region codes for states/regions https://en.wikipedia.org/wiki/ISO_3166-2:US.
I went to the infusionsoft api docs ( https://developer.infusionsoft.com/docs/rest/#!/Contact/createContactUsingPOST ) and tried what you have but with the ISO region codes for states and it worked. I did need to convert all single quotes to double quotes for it to correctly add the contact using the documentation "try it" feature, so that might be another issue?
Here is the exact json string that I used: