APIs & Integrations

danhammari
Contributor

API v3 DateTime Format in PHP: Which Format Should I Provide?

SOLVE

Is there a particular format I should use when exporting a DateTime value for the PHP API library?

 

I am creating deals via the API v3 CRM Deals endpoint using the PHP library.

I seem to be unable to set the closedate property for my deals and suspect this may be due to the datetime format that I am providing.

  • CLASS: \HubSpot\Client\Crm\Deals\Api\BasicApi.php
  • METHOD: create($simple_public_object_input)

The create example in the API Developer Docs provides the following value when setting the closedate:

This format doesn't seem to quite align with the DateTimeInterface::ATOM constant in PHP:

Should I instead export the DateTime value as a UNIX_TIMESTAMP, multiply that value by 1000 to add milliseconds, and provide that number to the PHP library? 

 

Or should I simply supply a raw DateTime object and trust that the PHP Library will take care of the export format for me?

0 Upvotes
1 Accepted solution
danhammari
Solution
Contributor

API v3 DateTime Format in PHP: Which Format Should I Provide?

SOLVE

It looks like the only option that works is when I convert the DateTime to a UNIX TIMESTAMP, then multiply that number by 1000 to convert it to microseconds.

  • $milliseconds = $datetime_object->getTimestamp() * 1000;

 

When I supplied a DateTime object I received this error message:

  • Invalid input JSON on line 1, column 68: Cannot deserialize instance of `java.lang.String`  (truncated...)

 

When I supplied an RFC3339 (ATOM) DateTime Format I received this error message:

  • Property values were not valid: [{\"isValid\":false,\"message\":\"2021-04-23T06:00:00+00:00 (truncated...)

View solution in original post

2 Replies 2
danhammari
Solution
Contributor

API v3 DateTime Format in PHP: Which Format Should I Provide?

SOLVE

It looks like the only option that works is when I convert the DateTime to a UNIX TIMESTAMP, then multiply that number by 1000 to convert it to microseconds.

  • $milliseconds = $datetime_object->getTimestamp() * 1000;

 

When I supplied a DateTime object I received this error message:

  • Invalid input JSON on line 1, column 68: Cannot deserialize instance of `java.lang.String`  (truncated...)

 

When I supplied an RFC3339 (ATOM) DateTime Format I received this error message:

  • Property values were not valid: [{\"isValid\":false,\"message\":\"2021-04-23T06:00:00+00:00 (truncated...)
dennisedson
HubSpot Product Team
HubSpot Product Team

API v3 DateTime Format in PHP: Which Format Should I Provide?

SOLVE

@danhammari 

for posterity: here is the doc on timestamp format

Thanks,

Dennis




HubSpot Community Developer ShowMake sure to subscribe to our YouTube channel
where you can find the HubSpot Community Developer Show
0 Upvotes