Unable to update timestamp property in HubSpot

751 views Asked by At

I have a custom property for the contacts entity in HubSpot. This property is defined as field type "Date Picker" in my code C#, I have a contact object that I serialize with a property bound to this the hub spot property. The property is of type long.

[JsonProperty(PropertyName = "last_login_date")]
public double? lastLoginDate { get; set; }

The data in this field is always set to midnight and then also converted to a timestamp to pass along to HubSpot.

contact.properties.lastLoginDate = DateTimeToUTC(Convert.ToDateTime(LastLoginInfo.lastLoginDate.ToShortDateString()));

public static double DateTimeToUTC(System.DateTime dateTime)
{
    dateTime = System.DateTime.SpecifyKind(dateTime, DateTimeKind.Utc);
    var utcValue = ((DateTimeOffset)dateTime).ToUnixTimeMilliseconds();
    return utcValue;
}

The json data I am sending over to HubSpot is obtained as such: {"properties":{"last_login_date":1601856000000.0,"firstname":"Andrew","lastname":"Jacson","email":"[email protected]","phone":"3058675309","mobilephone":"3058675308"},"id":null}

The API call fails and throws the following error:

{"status":"error","message":"Property values were not valid: [{\"isValid\":false,\"message\":\"1601856000000.0 was not a valid long.\",\"error\":\"INVALID_LONG\",\"name\":\"last_login_date\"}]","correlationId":"7d73007a-bedd-4923-b055-b3318e32414b","category":"VALIDATION_ERROR"}



request.AddHeader("content-type", "application/json");
var json = JsonConvert.SerializeObject(contact);
request.AddParameter("application/json", json, ParameterType.RequestBody);

If I change the property type in Hubspot to say a text imput I get no errors. However, I need this property to be a date field.

2

There are 2 answers

0
CodeMilian On

The issue was when serializing the object it was appending a .0 at the end of the timestamp. I changed the property to a string on the c# side and I no longer experience the issue and the entity is updated correctly in HubSpot.

0
Long Nguyễn Hoàng On

In your case, it should be "1601856000000", not "1601856000000.0". Please refer to this link to make the proper conversion: https://www.epochconverter.com/.

Timestamp in milliseconds: 1601856000000

Date and time (GMT): Monday, October 5, 2020 12:00:00 AM