Set Pagination to Control the Number of Email Messages Returned at One Time

You can use pagination to control the number of email messages returned at one time by the Microsoft Office 365 Outlook Adapter.

To perform pagination, Microsoft provides an odata.nextLink property as part of the response message. If defined during Microsoft Office 365 Outlook Adapter configuration, this property is set to a URL that links to the next page of results. This feature enables you to return the results in a controlled fashion. See Use query parameters to customize responses.

This section provides a high-level overview of designing and running an integration that uses pagination to control the number of email messages returned by the Microsoft Office 365 Outlook Adapter at one time.

  1. Create a REST Adapter trigger connection and Microsoft Office 365 Outlook Adapter invoke connection.
  2. Create an application integration.
  3. Drag the REST Adapter into the integration canvas and create the following query parameters:

    The Edit Request Parameters page shows fields for Operation Name, Resource URI, and HTTP Methods. Below this is the Specify Query Parameters section, which includes Add and Remove buttons. Below this is a table with columns for Name and Data Type. Six query parameters are listed. All are string values.

  4. Drag the Microsoft Office 365 Outlook Adapter into the integration canvas and configure it as follows.
    1. On the Basic Info page, enter the name.
    2. On the Operations page, select Get messages to return a collection of emails from your mail box.
    3. On the Request Parameters page, select the query parameters to use to filter the content of email messages returned by the Microsoft Office 365 Outlook Adapter.

      The Edit Request Parameters page shows the Query Parameters field, which includes the label Enter name to filter. Below this is the Available Query Parameters section and the Selected Query Parameters section. Seven parameters are selected.

  5. Open the mapper and map the source REST Adapter query parameters to the target Microsoft Office 365 Outlook Adapter query parameters.

    The mapper shows the Sources, Mapping canvas, and Target sections. Seven query parameters are mapped from the source section to the target section.

  6. Drag a data stitch action below the Microsoft Office 365 Outlook Adapter to save the first set of results of the Microsoft Office 365 Outlook Adapter operation in a variable.

    The Configure stitch section shows the stitch name and the value set. The edit icon appears in the upper right.

  7. Create a variable in an assign action to save the odata.nextLink returned in the Microsoft Office 365 Outlook response.

    The Configure assign panel is shown. On the left are the Input sources (which is selected) and Functions tabs. The Sources tree is expanded to show the odata.nextLink element selected. On the right side, the Configure assign title is shown. An edit icon is on the right. Below this, the odata.nextLink element is set as the value for the parameter currentNextPage.

    The integration looks as follows.


    The integration shows a trigger, map action, invoke, stitch action, and assign action.

  8. Create a while action below the assign action to get the next set of email results. As long as the URL in the currentNextPage variable is not empty, the while action continues to iterate for more email messages from Microsoft. Using the query parameter only enables you to receive a maximum of 1000 email messages. However, using a while loop lets you iterate for more email messages in a controlled fashion using currentNextPage.

    The Configure while panel shows a loop of currentNextPage != '' set.

    1. Create a second Microsoft Office 365 Outlook Adapter invoke connection.
    2. On the Operations page, select Get messages.
    3. On the Configure Request page, select only the _nextLink query parameter. This parameter is for passing the currentNextPage variable created in the assign action.

      The query parameters defined in the first Microsoft Office 365 Outlook Adapter do not require reselection in the second adapter. Those defined query parameters are automatically appended to the end of the _nextLink query parameter.


      The Sources, Mapping canvas, and Target sections are shown. currentNextPage is mapped to NewLink.

    4. Create a second data stitch action to collect page results.

      The Configure stitch panel is shown. The Input sources tab is shown on the left. It has been expanded to show a value under GetOutlookEmails. One of those values, 0x617472_odata.nextLink has been set to a parameter named currentNextPage.

    When complete, the while action portion of the integration looks as follows.


    The integration shows a while action that consists of a map action, invoke, and stitch action.

  9. Activate the integration.
  10. Click the Actions Actions icon menu, and select Run.
  11. Specify values for the query parameters, then click Run:
    URI Parameter Value Result of Setting
    trigger_query_param_for_top 2 Returns two emails.
    trigger_query_param_for_filter isRead eq true Returns emails that have been read.
    trigger_query_param_for_select subject, isRead, createdDateTime Returns emails that include these object properties.
    trigger_query_param_for_orderby createdDateTime Orders the results by the date and time created.
    When processing completes, the Response section shows many results due to pagination. All results returned include the following:
    • The subject, isRead, and createdDateTime object properties
    • The isRead object property set to true
    • The odata.etag and id internal parameters returned by the Microsoft APIs


    The Response section is shown with labels for Status and Instance ID. Below this, the Body column and the Headers column are shown. The contents of the header are described above this image.

  12. View the activity stream. The while loop iterated twelve times to control the delivery of emails messages to the Microsoft Office 365 Outlook Adapter in twelve pages, instead of returning all email messages at the same time.

    The activity stream is shown. The while loop iterated twelve times to control the delivery of emails messages to the Microsoft Office 365 Outlook Adapter in twelve pages, instead of returning all email messages at the same time.