Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Requirements for the API implementing paged results #30744

Closed
Heer-Boaz opened this issue May 7, 2019 — with docs.microsoft.com · 8 comments
Closed

Requirements for the API implementing paged results #30744

Heer-Boaz opened this issue May 7, 2019 — with docs.microsoft.com · 8 comments

Comments

Copy link

There appears to be no description of the requirements on how to support pagination from the perspective of the API that is being invoked by Logic Apps.
Now, we are getting an "InvalidPageResponse", related to a property 'value' missing in the result body.


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

@mike-urnun-msft
Copy link
Contributor

Hi @Heer-Boaz Thank you for your feedback! We will review and update as appropriate.

@DixitArora-MSFT
Copy link
Contributor

@ecfan Just checking if we need to define this.

@Heer-Boaz
Copy link
Author

I've got it working by trial and error.
Unfortunately, the out-of-the-box support for paging has some limits (e.g. only the rows in value are part of the task output).

Requirements for returning paginated responses (JSON)

JSON-body of the response needs to include the properties:

  • nextLink: the URI that contains the next paged result. This property should only be present in the body when there are more pages available. Otherwise, this property should not be present in the body.
  • value: an array containing the results of the requested page. The objects that are returned in the response body are aggregated.

The HTTP-response code is 200.

Example paginated API responses

Response #1

{
  "property": "Hello",
  "nextLink": "http://localhost:7071/api/PaginationFunction?pagetoken=Boem",
  "value": [
    {
      "Name": "name1",
      "Description": "desc1"
    },
    {
      "Name": "name11",
      "Description": "desc11"
    }
  ]
}

Response #2

{
  "property": "Hello Boem",
  "nextLink": "http://localhost:7071/api/PaginationFunction?pagetoken=Klaar",
  "value": [
    {
      "Name": "name3",
      "Description": "desc3"
    }
  ]
}

Response #3

{
  "property": "Hello Klaar",
  "value": [
    {
      "Name": "name2",
      "Description": "desc2"
    },
    {
      "Name": "name22",
      "Description": "desc22"
    }
  ]
}

Example logic app task output

{
  "value": [
    {
      "Name": "name1",
      "Description": "desc1"
    },
    {
      "Name": "name11",
      "Description": "desc11"
    },
    {
      "Name": "name3",
      "Description": "desc3"
    },
    {
      "Name": "name2",
      "Description": "desc2"
    },
    {
      "Name": "name22",
      "Description": "desc22"
    }
  ]
}

@DixitArora-MSFT
Copy link
Contributor

@Heer-Boaz I am glad that the issue is resolved. For now will proceed to close this thread. If there are further questions regarding this matter, please tag me in your reply. We will gladly continue the discussion and we will reopen the issue.

@ecfan
Copy link
Contributor

ecfan commented May 10, 2019

@Heer-Boaz & @DixitArora-MSFT, thanks for raising this issue. I think adding this info would be useful, so I'll open a work item. Thanks again!

@robinhalabicki
Copy link

Any progress on this? Pagination only works if the Payload results have "value".

@PRMerger17 PRMerger17 added the Pri2 label Apr 1, 2020
@mshparber
Copy link

My API (OKTA) returns rel="next" url in the RESPONSE HEADER.
Is this supported?

@mkilp91
Copy link

mkilp91 commented Oct 23, 2023

Unfortunately, the API I am using has the same issue as @mshparber. The "nextLink" and "value" keys are called "next" and "results" respectively in the model I am using.

I do have a work around, granted it is pretty annoying. That said, I am pretty new to programming so take it easy on me if this solution is a bit messy. Here are the steps:

  1. Initialize variables: integer: "count"=1, integer: "offset"=0, array: "response"=[]. Make sure that count is initialized to be greater than 0. It will be reset after the HTTP action returns a response.
  2. Create a Do Until loop where the condition is "@{variables('offset')}>@{variables('count')}"
  3. Within the loop create your HTTP action and use limit and offset query parameters. For example, the URI is "https://{your endpoint}?limit=100&offset=@{variables('offset')}".
  4. Add a Parse JSON action after the HTTP action. Content should come from the body of your HTTP request and then define your schema based on your API's model.
  5. Append to array @{variables('response')}. Value=@{body('Parse_JSON')?['results'].
  6. Set variable "count" from the value in the HTTP response.
  7. Increment offset by the value you set your limit parameter to. In my case 100.

Once the offset exceeds the count, the loop will stop and you now have an array of your paginated JSON (response).

I really wish there was a way to tell the HTTP action that a key in your payload is the same as the value key the HTTP action uses to paginate responses. However, this workaround has been a viable solution in my automation development.

I hope this helps!

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

No branches or pull requests

9 participants