【发布时间】:2021-01-20 23:34:18
【问题描述】:
我在 HubSpot 中有一个联系人实体的自定义属性。此属性在我的代码 C# 中定义为字段类型“日期选择器”,我有一个联系人对象,我使用绑定到此中心点属性的属性对其进行序列化。该属性的类型为 long。
[JsonProperty(PropertyName = "last_login_date")]
public double? lastLoginDate { get; set; }
此字段中的数据始终设置为午夜,然后也转换为时间戳以传递给 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;
}
我发送到 HubSpot 的 json 数据是这样获得的: {"properties":{"last_login_date":1601856000000.0,"firstname":"Andrew","lastname":"Jacson","email":"sjackson@test.com","phone":"3058675309","mobilephone ":"3058675308"},"id":null}
API调用失败并抛出如下错误:
{"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);
如果我将 Hubspot 中的属性类型更改为输入文本,则不会出错。但是,我需要将此属性作为日期字段。
【问题讨论】:
标签: c# api datetime timestamp hubspot