When I paginate through next_cursor, I get a different number of channels every time I hit the URL through NodeJS function.
Once the total channels fetched is 7488 another time it is 300. It differs every time I run the program.
URL : https://slack.com/api/conversations.list?types=public_channel&cursor={cursor}=&exclude_archived=true&token={token}
The issue is due to the rate limit of slack. conversation.list comes under tier 2 rate limit. That is only maximum 20 requests per minute.
function fetchData(){
getResponse(url);
function getResponse(url) {
let tempData = '';
https.get(url, (resp) => {
resp.on('data', (chunk) => {
tempData += chunk;
});
resp.on('end', () => {
try{
tempData = JSON.parse(tempData);
if(tempData.channels){
resultData.push(tempData.channels);
}
if (tempData.response_metadata && tempData.response_metadata.next_cursor) {
if(tempData.response_metadata.next_cursor === ''){
return resultData;
}
let cursorIndex = url.indexOf('cursor');
let newUrl = url.slice(0,cursorIndex);
let token = apiConstants.SLACK_API['ACCESS_TOKEN'];
let nextCursor = tempData.response_metadata.next_cursor.slice(0,tempData.response_metadata.next_cursor.length-1);
nextCursor = nextCursor + "%3D";
newUrl = newUrl + 'cursor=' + nextCursor + '&token='+ token;
getResponse(newUrl);
} else {
return resultData;
}
}catch(err){ console.log(err);} } } }