Skip to content

List endpoints return a bare JSON array, but types/cast assume { Data, TotalRecords } #38

Description

@asachs01

Summary

The library models list endpoints (computers.list(), clients.list(), locations.list(), alerts.list(), scripts.list(), etc.) as returning { Data: T[]; TotalRecords?: number }, but the live ConnectWise Automate REST API returns a bare JSON array for these endpoints.

Because HttpClient.handleResponse does a blind return response.json() as Promise<T> (no runtime validation), the mismatch compiles cleanly and only surfaces at runtime. Any consumer that reads response.Data gets undefined and crashes (e.g. response.Data.lengthCannot read properties of undefined (reading 'length')).

This was hit downstream in connectwise-automate-mcp (issue #35), which now compensates by normalizing both shapes at its boundary. But every other SDK consumer re-inherits the same bug, so it should be fixed at the source.

Corroboration that list endpoints return a bare array: the widely-used connectwise-rest client types Automate /api/v1/Computers as Promise<Array<LabTechModelsComputer>>.

Suggested fix

  1. Correct the *ListResponse types to reflect the real bare-array shape (or make the resource methods unwrap a { Data, TotalRecords } envelope into a typed array + total if some deployments/endpoints really do wrap — confirm against a live server).
  2. Replace the unchecked response.json() as T cast in HttpClient with runtime-validated parsing (or at least a normalization layer for list endpoints) so a shape drift surfaces as a clear error rather than a downstream undefined crash.
  3. PaginatedIterable (listAll()) reads response.Data and has the same assumption — fix it alongside.

Affects v1.0.2.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions