First of all, your bot access token has the right to read posts and attachments under a team/chat/conversation the bot is a member of.
In your case, I don't see the code nor the environment so it's hard for me to tell what could be wrong. This is how I could successfully download a binary file attachment in my bot using Node JS.
const url = require('url')
try{
var attachmentUri = "https://dl.mvp.ringcentral.com/file/NNN"
var accessToken = "Valid-AccessToken"
download(attachmentUri, accessToken, (err, content) => {
console.log("Done")
})
}catch(e){
console.log(e)
}
var https = require('https');
const download = function(attachmentUri, token, cb) {
var file = fs.createWriteStream("testing.png");
var u = url.parse(attachmentUri);
var options = {
host: u.host,
path: u.pathname,
method: "GET",
headers: {
Authorization: `Bearer ${token}`
}
}
const req = https.request(options, res => {
var chunks = [];
res.setEncoding('binary');
res.on('data', (chunk) => {
chunks += chunk;
}).on('end', () => {
file.write(chunks, 'binary');
file.on('finish', () => {
console.log('File Saved !');
});
res.pipe(file);
})
})
req.on('error', error => {
console.error(error)
})
req.end()
}If you believe that your code is correct and you still receive the error, I recommend to submit a dev support ticket so you can provide more details for the investigation.