APIs & Integrations

danhammari
Colaborador(a)

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

resolver

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 Avaliação positiva
1 Solução aceita
danhammari
Solução
Colaborador(a)

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

resolver

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...)

Exibir solução no post original

2 Respostas 2
danhammari
Solução
Colaborador(a)

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

resolver

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
Equipe de Produto da HubSpot
Equipe de Produto da HubSpot

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

resolver

@danhammari 

for posterity: here is the doc on timestamp format

0 Avaliação positiva