microsoftgraph / microsoftgraph/msgraph-sdk-python

A Way to get all list values for a CollectionResponse?

Abierto
#919 3 comentarios 0 reacciones 1 asignado Ver en GitHub

@jussihi ya está trabajando en esto.

Desde el 8/10/2024.

Needs: Attention :wave: question
Lenguaje dominante
Python
Estrellas
630
Forks
96
Merge medio
15 h 20 min
PR fusionados (30 d)
3

Descripción

Is your feature request related to a problem? Please describe the problem.

Is there already a way to get all items for a CollectionResponse? Currently the API/SDK returns only a page of results, and then we need to fetch more by using odata_next_link.

Is there a way to get all results in a single request?

I have made a helper function which I use, is this the best way;

# Takes in any CollectionResponse
async def get_complete_paginated_list(
    request_builder_func: Any,
    request_configuration: Optional[Any] = None
) -> List[Any]:
    ret: List[Any] = []
    collection_response: Any = await request_builder_func.get()

    # Nothing to return here
    if collection_response is None or collection_response.value is None:
        return ret

    def add_response_items(response: Optional[Any], items: List[Any]) -> None:
        if response is not None and response.value is not None:
            for item in response.value:
                items.append(item)

    # Add initial results
    add_response_items(collection_response, ret)

    # Iterate pages
    while collection_response is not None and collection_response.odata_next_link is not None:
        collection_response: Optional[Any] = await request_builder_func.with_url(collection_response.odata_next_link).get(request_configuration = request_configuration)
        if collection_response is not None:
            add_response_items(collection_response, ret)

    return ret

It can then be used like this;
mailfolders: List[MailFolder] = await get_complete_paginated_list(graph_client.users.by_user_id(user_id).mail_folders)

Describe the solution you'd like.

something like what I've made

Additional context?

No response

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.