Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(php): Fix date formatting in ObjectSerializer #372

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

UNIT23
Copy link

@UNIT23 UNIT23 commented Apr 5, 2024

Problem :
Function getVideosPlays() from Analytics PHP Api throw 400 error :
ApiVideo\Client\Exception\HttpException: HTTP 400 returned. {"type":"https:\/\/docs.api.video\/reference\/request-invalid-query-parameter","title":"A query parameter is invalid.","status":400,"detail":"This value is not a valid date.","name":"from"}

Code :
$dateFrom = (new DateTime())->sub(new DateInterval('P1D')); $apiVideoSessions = $this->client->analytics()->getVideosPlays($dateFrom, 'videoId');

Because :
In src/Api/AnalyticsApi.php :

  • line 103 : $queryParams['from'] = ObjectSerializer::sanitizeForSerialization($from, 'date');
  • line 104 : $queryParams['to'] = ObjectSerializer::sanitizeForSerialization($to, 'date');
  • line 209 : $queryParams['from'] = ObjectSerializer::sanitizeForSerialization($from, 'date');
  • line 214 : $queryParams['to'] = ObjectSerializer::sanitizeForSerialization($to, 'date');

Second parameter of ObjectSerializer::sanitizeForSerialization must be $type and not $format.

In ObjectSerializer::sanitizeForSerialization($data, $type = null, $format = null) :
if ($data instanceof \DateTime) { return ($format === 'date') ? $data->format('Y-m-d') : $data->format(self::$dateTimeFormat); }

Fix :
if ($data instanceof \DateTime) { return ($type === 'date' || $format === 'date') ? $data->format('Y-m-d') : $data->format(self::$dateTimeFormat); }

@UNIT23 UNIT23 marked this pull request as draft April 5, 2024 12:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant