Recently, I’ve been creating Slack bot with Javascript. And then I got an error that is token type, which is given in team.accessLogs()
funcntion is not allowed. Detailed error is below:
Error: An API error occurred: not_allowed_token_type
at platformErrorFromResult (/bot-todo/node_modules/@slack/bolt/node_modules/@slack/web-api/dist/errors.js:56:33)
at WebClient.apiCall (/bot-todo/node_modules/@slack/bolt/node_modules/@slack/web-api/dist/WebClient.js:181:56)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async getIPAddress (file:///bot-todo/program-test.js:18:27) {
code: 'slack_webapi_platform_error',
data: { ok: false, error: 'not_allowed_token_type', response_metadata: {} }
}
Code:
'use strict';
import bolt from '@slack/bolt';
import chalk from 'chalk';
import dotenv from 'dotenv';
dotenv.config();
import fs from 'node:fs';
import readline from 'readline';
const rs = fs.createReadStream('./meaning-data.csv');
const rl = readline.createInterface({ input: rs});
const app = new bolt.App(
{ token: process.env.SLACK_BOT_TOKEN,
appToken: process.env.SLACK_APP_TOKEN,
socketMode: true,
logLevel: 'debug'
});
async function getIPAddress(n, page) {
try {
const userInformation = await app.client.team.accessLogs({
token: "xxxx",
before: 1701620221,
count: n,
page: page,
limit: 1,
});
console.log(chalk.blue(userInformation));
} catch(error){
console.error(chalk.red(error));
}
}
getIPAddress('1', "12");
Up until now, I tried:
- Test whether this token is valid or not with auth.test api
- Given “admin” scope to the user scope to use
accessLogs()
function - make sure other api that is working with same
SLACK_APP_TOKEN
in code.
Images↓
admin user scope
test with auth.test()
api succeed
“not_allowed_token_type” error occured with api tester of team.accessLogs()
function
Based on the above facts, why test with auth.test()
function succeed, although test with team.accessLogs()
function failed?
8
The team.accessLogs
method is only available for the user
token that has been granted the admin
scope, not the bot
token. This is documented on the method’s page here: https://api.slack.com/methods/team.accessLogs.
The user token starts with “xoxp-” and not “xoxb-“.
5
It looks like you are passing team_id
and bot token (xoxb-*) to the request, but the documentation says that ‘The team_id is only relevant when using an org-level token.’. So perhaps try to omit the team_id or use the org-level token?
(sorry I don’t have enough rep to comment)