Valid formats for date fields when posting via HubSpot API


#1

Hi.

I’m trying to figure out a (or the) correct format for sending date parameters via a POST request to a form with a date picker via the /uploads/form/v2/:portal_id/:form_guid endpoint.

I first tried yyyy-mm-dd format, e.g., for August 15, 2016 I sent 2016-08-15. Although this seems to be interpreted correctly when you view submissions for that particular form, when looking at the associated Contact that it creates or updates, the date field displays Invalid date in red.

On the other hand, sending the date in mmm dd yyyy, e.g. Aug 15 2016, displays the date as Invalid date when viewing submissions to the form, but when drilling down to a specific Contact, the date displays correctly.

Assuming I’d prefer the latter — that this date get written to the Contact’s record correctly — is mmm dd yyyy the format of choice to send via this endpoint? Is there a standard format for sending date parameters to the HubSpot API that would be correctly interpreted in both cases? Can I decouple the way dates are displayed in HubSpot and how I choose to send them via the API by some admin setting?

Thanks for any help you can provide.


#2

Hi @O-I

Date properties need to be set as UNIX formatted timestamps, in milliseconds. As an example, you would use 1430438400000 as the value for the time 01 May 2015 00:00:00 UTC. This goes for form submissions as well as updates made through the Contacts API.

More details can be found here:


#3

Thanks for the quick response and helpful link, @dadams.


#4

If anyone stumbles upon this thread and is looking for a solution using Ruby/Rails, here’s how I had to do it:

def hubspot_formatted_date(date)
  return nil if date.nil?

  Time.utc(date.year, date.month, date.day).strftime('%s%3N')
end

That last strftime puts it in 13-digit format.


#5

I am having some trouble submitting post requests to create a deal because the timestamp value for a date picker property is not being accepted by the hubspot api. Here is the timestamp value 1206331200000. The date is 3/24/2008. The API accepts the value of 1430438400000 that you list above but not my value. I have run my value through some online converters and it shows as being valid. Why is the Hubspot API returning bad request when this value is included in the request.


#6

Hi @InProductionDev,

That timestamp value is midnight 3/24/2008 ET, not midnight UTC. UTC midnight 3/24/2008 would be 1206316800000.