Skip to content

No type for API responses that return a list of values #235

Open

Description

@M1kep

I've found that when querying endpoints such as https://graph.microsoft.com/v1.0/groups I cannot find any types that match up with the response structure shown below:

interface valuesResponseExample<T> {
    @odata.context: string,
    @odata.nextLink?: string,
    value: T[]
}

Is this the intended behavior, and if so what is the suggested method for working around this?
AB#8341

Activity

  1. ghost removed on Mar 1, 2021
  2. nikithauc commented on Mar 4, 2021

    @nikithauc
    Contributor

    Michael (@M1kep)
    This is intended behavior.

    Example of using the Group type in this case -

    const res = await client.api("/groups").get();
    const group = res.value[0] as Group;

    Please let me know if you have any more questions.

  3. markfields commented on Mar 25, 2021

    @markfields

    +1. Having types that encompass the @odata fields (both in the envelope and inside the entity) would be cool, especially for delta sync endpoints to easily get at @odata.nextLink and @odata.deltaLink.

  4. markfields commented on Mar 25, 2021

    @markfields

    I defined my own type for this purpose:

    type ODataResponse<T> = {
        [key: string]: any;
        value: T[];
    }

    Maybe it could be expanded upon to actually list some the valid @odata properties for ease of use if you need them in code? (e.g. @odata.nextLink)

  5. richban commented on Jun 23, 2021

    @richban

    Bit out of topic but how can I remove the @data props from each response?

    ss

  6. Jonas-Seiler-Wave commented on Mar 1, 2022

    @Jonas-Seiler-Wave

    Michael (@M1kep) This is intended behavior.

    I think this really shouldn't be the intended behavior

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions