microsoftgraph / microsoftgraph/msgraph-sdk-python

A Way to get all list values for a CollectionResponse?

オープン
#919 コメント 3 件 リアクション 0 件 担当者 1 名 GitHub で見る

@jussihi がすでに取り組んでいます。

2024年10月8日 から。

Needs: Attention :wave: question
主要言語
Python
スター
630
フォーク
96
平均マージ
15時間 20分
マージ済み PR(30日)
3

説明

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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。