[SOLVED] Inside function: The current user is not authorized to perform the requested action
- 0
- Databases
- Functions
- Self Hosted
I'm getting the above error when I'm trying to call listDocuments inside a function. Aren't default clients using APPRITE_API_KEY in functions supposed to be able to make actions regardless of permissions? Or I'm doing something wrong?
Here is the function:
import { Client, Query, Databases } from 'node-appwrite'
const client = new Client()
client
.setEndpoint(process.env.APPWRITE_ENDPOINT)
.setProject(process.env.APPWRITE_FUNCTION_PROJECT_ID)
.setKey(process.env.APPWRITE_API_KEY)
const db = new Databases(client)
export default async ({ req, res, log, error }) => {
const results = await db.listDocuments('MYDB', 'Users', [Query.equal('UserID', req.body.userId)])
log(results)
return res.send('ok')
}
does your api key have access to database scopes?
wdym? the api key is coming directly from appwrite, it's not set by me
I guess this is the key named Generated for Template
could you share the execution logs of the function?
i just logged out process.env.APPWRITE_API_KEY and it's undefined
i'm invoking this function with an event, can that cause such problem?
hmm, seems like I need to set this on my own, the docs isn't really clear about this
I expected to have the default generated always available
which template you are using?
nope. events are only used to trigger the function when certain events happen
Honestly, I have no clue 😄 For sure I didn't generate this API key on my own, it's just there in my project 😄
happens😆
Just executing any function, make sure that the enviroment vars are set
this could be the reason
yeah, it was
now it's all good
Awesome!
[SOLVED] Inside function: The current user is not authorized to perform the requested action
Recommended threads
- TablesDB can't be used in Appwrite Funct...
I have written a function (DART) and it won't deploy. Here is what I get : 2026-03-14T17:09:41.459693680Z Compiling ... 2026-03-14T17:09:42.915619217Z ../build...
- Realtime for files() works almost well, ...
I have been trying to make use of realtime, today (14.03.26) I have pulled all the latest versions of docker images, and sdk available. Whats working: - Conn...
- Local appwrite run functions --user-id n...
Hi, I'm running into an issue when testing Appwrite functions locally with user impersonation. I'm using a self-hosted Appwrite instance and running functions ...