Back

API key doesn't have permission even though it has all scopes

  • 0
  • Self Hosted
  • Web
Gybrid
9 May, 2024, 13:56

Hi All, I seem to be having issues with nodejs and the sdk.

I've setup an API key which has all scopes for the project, but I keep getting the "The current user is not authorized to perform the requested action." error.

If I change the collection permission settings so that 'all guests' can do all actions it works fine, but I thought the API keys didn't use the permission settings of the collection, so I'm a little confused. Any suggestions?

TypeScript
const dotenv = require("dotenv");
dotenv.config({ path: "./config.env" });

//const mapping from process.env here

const client = new sdk.Client()
  .setEndpoint("https://my.fqdn.here/v1")
  .setProject(APPWRITE_PROJECT)
  .setSession(APPWRITE_API_KEY);

const databases = new sdk.Databases(client);

async function getDocuments() {
  try {
    const result = await databases.listDocuments(
      APPWRITE_DB, // databaseId
      APPWRITE_COLLECTION // collectionId
    );
    console.log(result);
  } catch (error) {
    console.log(error);
  }
}
getDocuments();
TL;DR
API key with all scopes is set up but getting "current user not authorized" error in nodejs sdk. Changing collection permissions to 'all guests' resolves it. Unsure why API keys don't bypass collection permissions. Possible solution: Check if API key is correctly set up on the server, and ensure collection permissions are not conflicting with API key permissions.
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more