1

I am trying to find some information on how to page data in the Microsoft Graph gem? Specifically paging over messages in a folder. There does not appear to be a PageIterator in the gem (similar to the c# implementation) to help with paging over the data. I see that there is a top and skip method in the request builder, but that seems to be completely ignoring the odata_next_link returned in the first request. Any help would be greatly appreciated.

My code is currently looking like this and using the top and skip and returns duplicate messages:

    begin
      params = MicrosoftGraph::Users::Item::MailFolders::Item::Messages::Delta::DeltaRequestBuilder::DeltaRequestBuilderGetQueryParameters.new
      params.select = %w[sender subject body from toRecipients sentDateTime ccRecipients]
      params.filter = "receivedDateTime ge 2025-06-04T00:00:00Z"
      params.skip = 0
      params.top = 100
      request_configuration = MicrosoftKiotaAbstractions::RequestConfiguration.new
      request_configuration.query_parameters = params
      delta_request_builder = inbox_request_builder.messages.delta
      messages_fiber = delta_request_builder.get(request_configuration)

      while (messages_response = messages_fiber.resume)
        messages_response.value.each do |message|
          messages[message.id] = message
        end

        # next page
        params.skip += params.top
        messages_fiber = delta_request_builder.get(request_configuration)
      end
    rescue FiberError
      # Noop
    end

The message_response in this contains a odata_next_link property which is the url for the next page... but how do you feed that back in the ruby library?

There seems to be no information on the gem or Microsoft docs on how this should work.

0

1 Answer 1

2

Well i guess this is the answer

"Automatic paging is currently not supported with the Ruby SDK, we're working to enable this feature."

I got around this by building my own request information

# next page
unless (next_page_link = messages_response.instance_variable_get(:@odata_next_link))
  logger.debug { "No more messages" }
  break
end
request_info = MicrosoftKiotaAbstractions::RequestInformation.new
request_info.uri = next_page_link
request_info.http_method = :GET
error_mapping = Hash.new
error_mapping["4XX"] = lambda {|pn| MicrosoftGraph::Models::ODataErrorsODataError.create_from_discriminator_value(pn) }
error_mapping["5XX"] = lambda {|pn| MicrosoftGraph::Models::ODataErrorsODataError.create_from_discriminator_value(pn) }
messages_fiber = @request_adapter.send_async(request_info, lambda {|pn| MicrosoftGraph::Users::Item::MailFolders::Item::Messages::Delta::DeltaResponse.create_from_discriminator_value(pn) }, error_mapping)

This seems to work if anyone else needs this before they fix the gem

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.