APIs & Integrations

Not applicable

Valid formats for date fields when posting via HubSpot API

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.

0 Upvotes
5 Replies 5
Derek_Gervais
HubSpot Alumni
HubSpot Alumni

Valid formats for date fields when posting via HubSpot API

Hi @InProductionDev,

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

0 Upvotes
agjoligu
Participant

Valid formats for date fields when posting via HubSpot API

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.

0 Upvotes
gregblass
Member

Valid formats for date fields when posting via HubSpot API

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.

Dadams
HubSpot Employee
HubSpot Employee

Valid formats for date fields when posting via HubSpot API

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:

How should timestamps be formatted for HubSpot's APIs?

HubSpot API endpoints accept UNIX formatted timestamps in milliseconds. Most scripting languages have built-in functions or existing libraries that handle time conversion, but you must ensure that your timestamp values are in the correct UNIX...

0 Upvotes
Not applicable

Valid formats for date fields when posting via HubSpot API

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

0 Upvotes