Update Custom Date Picker in Deals through the API

My company has created a custom property under the deals section of Delivery Date (delivery_date) which is set to Date Picker. When I try to post to “Update a Deal” https://api.hubapi.com/deals/v1/deal/{dealID}?hapikey={apiKey}, I get a (400) bad request.

I am converting my DateTime to Unix Milliseconds.

My JSON string looks like this :
{
“properties”: [
{
“name”:“delivery_date”,
“value”:1542085200000
}
]
}

Does something look wrong with this request? Or am I supposed to do something before I am allowed to update this field?

The program I am writing is a quick C# windows form to upload an excel file and read the values to a model, convert to JSON, and update the selected Deals by DealID. I am testing various fields before I move everything to a single request. So far, I can’t figure out why this field won’t accept the Unix Milliseconds.

Thank you,

KO

Error was converting time for Date Picker. Has to be put in UTC.

Welcome, @kobrien.

I’m glad you were able to find a solution so quickly!

For others viewing this topic, check out the How should timestamps be formatted for HubSpot’s APIs? article for additional information.

Hi,

I was struggling on this as well. Thanks for your post.

For those who wanna test that your timestamp is based on midnigth UTC you can check it through this website: https://www.epochconverter.com/
For those using momentjs:
``moment.utc(your_date, ‘YYYY-MM-DD’).valueOf()``
Make sure to replace ‘YYYY-MM-DD’ with your date format.

The datepicker field wants a Unix timestamp with microseconds, but it must be the exact value of midnight in UTC. It will choke on your localized time zone. Here is how I set the value in PHP:

$target_date = date( 'Y-m-d', strtotime( 'tomorrow' ) );$timezone_object = new \DateTimeZone( 'UTC' );
$date_object = new \DateTime( $target_date, $timezone_object );
$datepicker_value = $date_object->format( 'U' ) * 1000;

PHP’s DateTime object will output a Unix timestamp in seconds, so you have to multiply by 1000 to convert the value to include microseconds.

In input, from C#, has to be that you convert it to a LONG. Specifically, a UNIX TIME milliseconds WITHOUT timezone offset.

public static long ToUnixTimeMilliseconds(this DateTime dateTime)
{
 var dateMidnight = DateTime.ParseExact(dateTime.ToString("yyyyMMdd"), "yyyyMMdd", CultureInfo.InvariantCulture);
 var offset = new DateTimeOffset(dateMidnight.Date, TimeSpan.Zero); // Removed UTC offset
 return offset.ToUnixTimeMilliseconds();
}