Skip to content

[Bug] Date fields returned through API are being lost to auto JSON deserialisation in Powershell 6+ #101

Description

@twoStickCrew

Summary
Date time fields returned from API calls are subjected to automatic deserialisation by the ConvertFrom-Json cmdlet. These fields are sporadically lost or have the dd MM fields switched due the loss of precision during the deserialisation resulting in inconsistent outputs. I found this in the Get-TeamViewerConnectionReport cmdlet but it stands to reason that all date time fields would be affected

Expected Behavior
Preventing the auto deserialisation of date time fields using the -DateKind string parameter (introduced in PS7.5) in the line return ((Invoke-WebRequest -UseBasicParsing @PSBoundParameters).Content | ConvertFrom-Json -DateKind String) in function Invoke-TeamViewerRestMethod prevents the loss of precision and allows the later call to [DateTime]::Parse($InputString) to correctly output the datetime in the local machine's culture format.

Setps To Reproduce
Describe the steps to reproduce the behavior:

  1. Call Get-TeamViewerConnectionReport
  2. Compare output to raw API output call (or non-deserialised call ) to https://webapi.teamviewer.com/api/v1/reports/connections
invoke-TeamViewerPing
True
$count=0
Get-TeamViewerConnectionReport -limit 1000 | %{ $_.enddate ?? ($count++) | out-null ; $_.startdate ?? ($count++) | out-null}
$count
954
$count=0
((Invoke-WebRequest -Uri "https://webapi.teamviewer.com/api/v1/reports/connections" -Method Get -Headers $header -ContentType application/json -ErrorVariable Errrrrrr).Content | Convertfrom-json -DateKind String).records |  %{ $_.end_date ?? ($count++) | out-null ; $_.start_date ?? ($count++) | out-null}
$count
8

Reference for deserialisation in ConvertFrom-Json on PS6+

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugIndicates an unexpected problem or unintended behavior

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions