• Skip to primary navigation
  • Skip to main content
Sal Ferrarello
  • About Sal Ferrarello
  • Speaking
  • Connect
    Mastodon GitHub Twitter (inactive)
You are here: Home / Solution / HubSpot API call fail INVALID_DATE not midnight!

HubSpot API call fail INVALID_DATE not midnight!

Last updated on May 21, 2019 by Sal Ferrarello

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' );
Sal Ferrarello
Sal Ferrarello (@salcode)
Sal is a PHP developer with a focus on the WordPress platform. He is a conference speaker with a background including Piano Player, Radio DJ, Magician/Juggler, Beach Photographer, and High School Math Teacher. Sal can be found professionally at WebDevStudios, where he works as a senior backend engineer.

Share this post:

Share on TwitterShare on FacebookShare on LinkedInShare on EmailShare on Reddit
Warning! This is a draft, not a finalized post. See full draft disclosure.

Filed Under: Dev Tips, Draft, Programming, Solution Tagged With: DateTime, HubSpot

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Copyright © 2023 · Bootstrap4 Genesis on Genesis Framework · WordPress · Log in