Date not accepted by API - timezone problem ?

Highlighted
New Contributor

Hello, I'm have a problem posting date values to HS via the API.

HS is setup with a custom property with the field type set to 'Date picker'.

 

As an example, the date I'm trying to push is 1 Sept 2020 BST (that's UTC+1)

which is equivalent to 31 Aug 2020 23:00 UTC

The HS documentation states timestamp should be UTC so it makes sense to me to base the Unix timestamp calculation off the UTC date (31 Aug 23:00 and not 1 Sep). This converts to 1598914800000 (milliseconds).

Note: calculated in C# and doubled checked with https://www.unixtimestamp.com 

FAQ: https://developers.hubspot.com/docs/api/faq#:~:text=The%20HubSpot%20APIs%20accept%20two,e.g.%202020%...

 

The problem is the timestamp is rejected by the HS Api.

The only way I can get this to work is to use the date 1 Sept and treat as UTC (but its not!) and post the ts for this ie 1598918400000

 

Can someone clarify what the correct approach is, I'm unsure How this will handle timezone changes eg when BST ends.

Reply
0 Upvotes
3 Replies 3
Highlighted
HubSpot Moderator

Hey @spikedev,

 

When looking to store both the date and time on a HubSpot property, you should use the datetimefield type.

 

The date pickerfield type can only store date - not the time. As such, while it is possible to use a millisecond timestamps, the values must be set to midnight UTC for the desired date. 

 

Reply
0 Upvotes
Highlighted
New Contributor

Hi @WendyGoh 

 

Thanks - I think I just need to ignore the timezones and send as I'd expect to see in HS

1 Jan 2021 (which is GMT) as 1609459200000

and 1 Sept 2020 (which is BST) as 1598918400000 (ignore that its BST and treat as UTC)

 

For what its worth - I don't remember there being a date time field; I've doubled checked and can only see Date pikcer in the list (screen attached bottom). But this doesn't really matter since I do just want dates.

 

Also I did try to send in the format YYYY-MM-DD which the FAQ also mentions but the API rejected my request. 

 

 

hubspot-fieldtypes.png

Reply
0 Upvotes
Highlighted
HubSpot Moderator

Hey @spikedev,

 

I was able to create a contact with the following body:

 

 

{
  "properties": {
    "newdatetimeproperty2": "1609459200000"
  }
}

 

 

Screen Shot 2020-07-14 at 10.33.30 AM.png

 

Does the timestamp 1609459200000 still shows up as error on your end? If so, could you share with me the portal ID and custom property in question? Additionally, what's the endpoint that you're using?

Reply
0 Upvotes