public cass PropertyOptions
{
public string Label { get; set; }
public string Value { get; set; }
public int DisplayOrder { get; set; }
}
public class HSContactProperty
{
public string Name { get; set; }
public string Label { get; set; }
public string Description { get; set; }
public string GroupName { get; set; }
public string Type { get; set; }
public string FieldType { get; set; }
public bool FormField { get; set; }
public int DisplayOrder { get; set; }
public List<PropertyOptions> Options { get; set; }
}
public class HSContactPropertyCollection
{
public List<HSContactProperty> HSContactProperties { get; set; }
}
Method that calls API:
public HSContactPropertyCollection GetContactProperties()
{
RestRequest request;
HSContactPropertyCollection proplist;
request = new RestRequest();
request.Resource = "contacts/v1/properties";
request.RequestFormat = DataFormat.Json;
request.AddParameter(TokenType, ApiToken);
proplist = Execute<HSContactPropertyCollection>(request);
return proplist;
}
public T Execute<T>(RestRequest request) where T : new()
{
RestClient client = new RestClient();
client.BaseUrl = BaseUrl;
var response = client.Execute<T>(request);
if (response.ErrorMessage != null && response.ErrorMessage.Length > 0)
{
throw new Exception("Error contacting HubSpot: " + response.ErrorMessage, response.ErrorException);
}
if (response.Content.IndexOf("error",0) > 0)
{
throw new Exception("Error in Hubspot Routine:" + response.Content);
}
return response.Data;
}
public class PropertyConverter : CustomCreationConverter<IContactProperty>
{
public override IContactProperty Create(Type objectType)
{
return new IContactProperty();
}
}