I am working with nodeJs - AWS lambda function, cognito userpool(AWS).
The requirement is of adding pagination feature, for that I am able to perform forward pagination with the help of https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_ListUsers.html,
but I am not able to find, what are the necessary steps to perform backward pagination, so that in UI, the users can scroll to previous and next pages without any issues using the endpoint created by me.
Can anyone help me into this?
Since you are directly accessing cognito API to do pagination for users,
What I would suggest is to pass a paginator value from UI to your API, that API will process your pagination in a loop,
For Example:
For the ease of understanding I will use pagination from 1
and each page is having 8 items,
So let's say,
You are sending querystringparameters something like this:
[your-api-endpoint]?page=1
Now, there is a variable counter which is the number of times your loop will execute,
Start a loop and in that loop call the Cognito API along with token handling capability, so if you call it 1 time you will have first 8 items.
Now let's take another scenario:
You are sending querystringparameters something like this:
[your-api-endpoint]?page=2
Now, the variable counter which is the number of times your loop will execute is set to 2,
Start a loop and in that loop call the Cognito API along with token handling capability, so if you call it you will have first 8 items, and loop will execute one more time since counter is set to 2, therefore you will have next 8 items and you can return that.
In this way your pagination will depend on input from front-end.
Since, I cannot found any specific sdk or code to implement backward pagination in cognito user pool, I have taken help of front end to store the pagination token sent from backend and fetch data accordingly.
So the scenario will be : For first time calling the API, the pagination token value(in headers/or the place where it is kept(params/body/headers)) will be NULL, and response will get a paginationtoken to move to next page, it can be stored in UI code, and use it to move to next page, again response will receive a paginationtoken, store it and proceed further to fetch next page data.
In order to move back to the previous page, use the stored pagination token and fetch the details accordingly.
Related
I have prepared a simple demo with react-router-dom 6 and react query.
I have a couple of routes and a fetch call that takes place on the first route (Home).
What I want to achieve is navigating to the About page or any other page and do not perform another request for a certain time period (maybe never again) but if I refresh the page I want to be able to re trigger the request to get the data.
I have tried using staleTime when but if I refresh the page I get no results, just a blank page. refreshInterval works on refresh but does not keep the data when I change routes.
I have also tried this pattern in this article but still I don't get the job done.
Probably it may be that something I don't understand but the question is how do I avoid making the same request over and over again, perfrm it only once but still being able to get the data if I refresh the page when navigating between different routes.
Demo
The solution to the problem came from one of the maintainers on the official github repo eventually and is related to adding placeholderData as an empty array instead of initialData and setting staleTime to Infinity in my case as I only want to perform the request once.
Setting placeholderData gives you the opportunity to show some dummy data normally until you fetch the real but in my case it seems to do the job. More to read regarding this at this source
const { isFetching, data: catImages } = useQuery({
queryKey: ["catImages"],
queryFn: getCatImages,
placeholderData: [],
staleTime: Infinity
});
I am using the marketing API
I have an issue with the pagination, it seems like it ignores the start and count.
I am using the start and count query parameters and no matter what number I put in the count, I get a response with all the results
I followed this document for pagination:
https://learn.microsoft.com/en-us/linkedin/shared/api-guide/concepts/pagination
I use this endpoint:
https://api.linkedin.com/v2/adAnalyticsV2
my parameters include:
start=0&count=10&q=statistics&timeGranularity=MONTHLY ....
in the response, I received 821 elements without any pagination. instead of 10 per page.
if I use the logic in the docs the values for start and count will not affect the results or the query
what am I doing wrong?
I don't want to use it without pagination and find out later that I missed records.
Thanks,
Roiy
I have used pagination to retrieve the posts of the organization, and its working for me
my api call is
api_url = "https://api.linkedin.com/v2/shares?q=owners&owners=urn%3Ali%3Aorganization%3A123456&sharesPerOwner=1000&count=100&start=0"
one thing importantly i noticed is this does not requires restli2.0 version(dont pass this in header)
This is more a design question than a lot of code.
I have my angular client query a mongodb collection via http and nodejs backend.
I want to paginate the result, so what I do is on the angular side, keep track of the page I'm on and the # of results I would like on each page, and I pass that on to my backend via an http call.
Then my backend has code that looks something like this:
schema.find({name: query, _userId: req.body._userId}).sort({ name: 'asc' }).limit(req.body.num_results).skip(req.body.page * req.body.num_results).then(response => {
Now I'd like to put "<" and ">" arrows on my client's html where every time left or right is clicked it traverses pages (via a new http call), but then make it so that "<" is disabled on page 0, and ">" is disabled on the last page of results. I've figured out how to disable the "<" - simply make the button go away when you're on page 0. But having trouble figuring out the best way to discover that I'm on the last page. One method could be for my backend to return the total number of results and then my front-end tracks where I am relative to the total #, but that involved another db call, move variables passed over http, more management on the front-end. Any ideas on how to implement a 'cleaner' solution?
Thank you.
You do not need to make any additional api call. You can return any additional information in the form of Http header when making api call. so, in this case return X-TOTAL-COUNT
how can you manage and endless scroll using a real time server connection instead pooling each time the user come to the end of the list on nodejs and react?
thanks
User pagination on the server and manage that on the frontend, when you react to end of the list then try to fetch next page data and just assign that data to the reactive variable. it will bind on FE after that.
It can't be possible to fetch at once if the number of records are more like in 5-6K+ range. If you fetch at once then it will take more than one min maybe more than that, so until the user can't wait on the same page he might reload the page or leave the page. you need to call API each time for better UI/UX.
You can use directives like this.
Just focus on scroll if you get events like user reached the end of the list then simply print something like this (use opacity to get more focus)
if your API returns zero new data then just print something like this
Edit after comment:
No, you don't need to set an open connection to the server, just call an API when you reach the end of the list, like you calling only when you want to fetch more data from the server.
if you fetch the live data and you think that duplicates might be present then you can filter at the backend and remove duplicates via matching unique key. if that's not feasible then you can remove on FE also because you have less no of data on FE as compare to BE.
SO like if you're calling a third party API to get data, so first fetch all records if you can and store on your DB then call an API from your FE to get data from your own DB it will make a simple and fast rendering.
I'm building an application which pulls down incident listings for my org via Pagerduty's REST API.
The GET /incidents endpoint does respond with more, offset, and other keys that are indicative of pagination being supported, and it does make intuitive sense on this endpoint, but I haven't been able to actually paginate these results:
Passing offset or limit as a query param returns a 403
Passing these in various forms in request headers just gets ignored entirely
Is there a way to paginate these results at all?
it might help to include the code you're using to make the request, or a curl request from the command line. Including pagination parameters shouldn't lead to a 403, so I'm thinking something else might be missing.
You should be able to paginate the lists using GET parameters, e.g
https://api.pagerduty.com/incidents?limit=20&offset=100
limit has a maximum value of 100, and limit + offset together must be less than 10,000. That might be why you were getting an error?
See here for additional details on the pagination parameters
Yes, it's possible to paginate the results.
After invoking the API method for the first time, you need to check the more response field value. If true, then you can call the API method again with an updated offset.
offset is related to the total results, and not the total pages.
The 403 error code response you're getting is most likely related to the user permissions and not with paginating results.