Search code examples
slack-api

Number of records returned from team.accessLogs API too large for page and count constraints?


API in question: https://api.slack.com/methods/team.accessLogs

The maximum page is 100 and the maximum records per page(count) is 1000 so total 100,000 records could potentially be returned. Since there is no way to limit the starting date for the accessLog, the results will continue to grow as more unique user/IP/useragent combinations are used until it reaches the limit at which point it wouldn't be possible to return all records. Is this correct?

Also, the documentation does not specify how the results are ordered?


Solution

  • You have mentioned correctly that typically you can fetch 100,000 records.

    But there is a way to limit the starting date.

    before argument in api lets you set the time before which you want the records.
    https://api.slack.com/methods/team.accessLogs#arg_before

    The records are fetched in reverse chronological order i.e. latest record first,
    and by default, the value of before argument is 'now'.
    After fetching first 100,000 records,
    set before argument value as "date_last" value from the last record.


    (keep in mind that before argument is inclusive of the value provided,
    therefore the last record will be repeated.
    To avoid it you can reduce "date_last" value by 1 )