APIs & Integrations

Not applicable

Update Custom Date Picker in Deals through the API

SOLVE

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

0 Upvotes
1 Accepted solution
Solution
Not applicable

Update Custom Date Picker in Deals through the API

SOLVE

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

View solution in original post

0 Upvotes
4 Replies 4
danhammari
Contributor

Update Custom Date Picker in Deals through the API

SOLVE

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.

MathieuH
Participant

Update Custom Date Picker in Deals through the API

SOLVE

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.

0 Upvotes
IsaacTakushi
HubSpot Employee
HubSpot Employee

Update Custom Date Picker in Deals through the API

SOLVE

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.

Isaac Takushi

Associate Certification Manager
0 Upvotes
Solution
Not applicable

Update Custom Date Picker in Deals through the API

SOLVE

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

0 Upvotes