EventDay / Infusionsoft.net

A C# Wrapper around the Infusionsoft.com API
16 stars 22 forks source link

ContactService.Load not returning custom fields #34

Open robmcleish opened 9 years ago

robmcleish commented 9 years ago

I am having trouble retrieving custom fields from the contact table.

I do not receive any error on this issue – I just do NOT receive the values for the custom fields that I am requesting. If I add a normal property like FirstName into SelectedFields then do receive its value back. I am using custom fields that I know are populated for the contact id in question, so I definitely should be receiving values back. Here is my calling code for ContactService.Load:

public string RetrieveCustomFieldFromContact(int contactID, string customFieldName) { const string methodName = "RetrieveCustomFieldFromContact"; var fieldValue = string.Empty; var customer = new Customer(Constants.InfusionSoftApplicationName, Constants.InfusionSoftAPIKey); var proxy = customer.Connect(); try { if (!customFieldName.StartsWith("")) { customFieldName = "" + customFieldName; } string[] selectedFields = { customFieldName }; var response = proxy.ContactService.Load(contactID, selectedFields); if (response.CustomFields.ContainsKey(customFieldName)) { fieldValue = response.CustomFields[customFieldName].ToString(); } } catch (Exception ex) { _utility.Log(LoggingType.Error, string.Format("{0} - An error occurred {1}", methodName, ErrorHelper.GetExceptionDetails(ex))); } return fieldValue; }

trbngr commented 9 years ago

I'm pretty sure that custom fields are prepended with an underscore.

string[] selectedFields = { string.concat("_", customFieldName) };

robmcleish commented 9 years ago

Yes my code is checking and prepending