🐛 Fix pagination issue with Slack node (#2328)

*  Fix pagination in Slack-Node

Previously, if you had more than 1k channels, only the first 1k would be loaded. Now with pagination, the limit is ~40k (due to rate limiting, which this doesn't handle well)

* 🐛 Fix issue with pagination

Continues with #2308

Co-authored-by: Fahrzin Hemmati <fahhem@users.noreply.github.com>
This commit is contained in:
Ricardo Espinoza 2021-10-19 00:04:58 -04:00 committed by GitHub
parent 0b1b4baaab
commit 3af223cd8e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -71,15 +71,21 @@ export async function slackApiRequestAllItems(this: IExecuteFunctions | ILoadOpt
const returnData: IDataObject[] = [];
let responseData;
query.page = 1;
query.count = 100;
//if the endpoint uses legacy pagination use count
//https://api.slack.com/docs/pagination#classic
if (endpoint.includes('files.list')) {
query.count = 100;
} else {
query.limit = 5;
}
do {
responseData = await slackApiRequest.call(this, method, endpoint, body, query);
query.cursor = encodeURIComponent(_.get(responseData, 'response_metadata.next_cursor'));
query.cursor = _.get(responseData, 'response_metadata.next_cursor');
query.page++;
returnData.push.apply(returnData, responseData[propertyName]);
} while (
(responseData.response_metadata !== undefined &&
responseData.response_metadata.mext_cursor !== undefined &&
responseData.response_metadata.next_cursor !== undefined &&
responseData.response_metadata.next_cursor !== '' &&
responseData.response_metadata.next_cursor !== null) ||
(responseData.paging !== undefined &&