When making a HubSpot API call to update a date picker field, I’m getting a response with response code 400
, error INVALID_DATE
, and the message includes not midnight!
.
{"isValid":false,"message":"1565207640 is at 2:46:47.640 UTC, not midnight!","error":"INVALID_DATE","name":"my_custom_date_picker_property"}
Reviewing the HubSpot documentation How should timestamps be formatted for HubSpot’s APIs? I notice two things:
HubSpot API endpoints accept UNIX formatted timestamps in milliseconds.
and
Date properties will only store the date, and must be set to midnight UTC for the date you want. For example, May 1 2015 would be 1430438400000 (01 May 2015 00:00:00 UTC). If you try to set a value that is not midnight UTC, you will receive an error.
Converting a Unix Timestamp
Working with a Unix Timestamp of 1557419523
(Thu, 09 May 2019 16:32:03 GMT
/ Thu, 09 May 2019 12:32:03 EDT
), I want to post the date as midnight for the local date (e.g. if local and GMT times have a different date I want to use the local date).
$unix_timestamp = 1557419523;
$dt = ( new \DateTimeImmutable() )->setTimestamp( $unix_timestamp );
$hubspot_date_picker_value = 1000 * strtotime( $dt->format( 'Y-m-d' ) . ' 00:00:00 GMT' );
Just faced this issue.
Useful snippet, thanks a lot