Back

I cannot access my collections with an api key from node.js server

  • 0
  • Databases
  • Self Hosted
  • Web
Luis
21 Oct, 2023, 18:19

I am trying to access my collections from a node.js server runtime with the 'node-apwrite' serve sdk.

I am getting the following error: /Users/agency/Documents/website/testing/node_modules/node-appwrite/lib/client.js:174 throw new AppwriteException(error.response.data.message, error.response.status, error.response.data.type, error.response.data); ^

AppwriteException [Error]: The current user is not authorized to perform the requested action. at Client.call (/Users/agency/Documents/website/testing/node_modules/node-appwrite/lib/client.js:174:31) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async Databases.createDocument (/Users/agency/Documents/website/testing/node_modules/node-appwrite/lib/services/databases.js:1691:16) at async createOtpToken (file:///Users/agency/Documents/website/testing/app.js:19:27) at async file:///Users/agency/Documents/website/testing/app.js:77:13 { code: 401, type: 'user_unauthorized', response: { message: 'The current user is not authorized to perform the requested action.', code: 401, type: 'user_unauthorized', version: '0.11.13' } }

Node.js v20.7.0

This is how I initialized the sdk: //Imports import * as sdk from 'node-appwrite' import { ID, Query } from "node-appwrite";

//AppWrite connection export const appwriteClient = new sdk.Client() .setEndpoint('https://cloud.appwrite.io/v1') .setProject('64fa13dd0e53cf8ad7e0') .setKey('c28260ba0463955d924274bdcfcf4967e06ecd360b48ae8d9afc16cd7bb65eb0c02a43211900e58a7e8e50c28928e486535c5c85e0dd5212ac033d4aacf9023a7e5575a44d5f44918dde954e013ecdbd2c99821c36f2aa05123e6f160fd7cf8ce192b0d0003abdcf31364c7e79450880b6616c81c2af0c845ec6d7a03730d7f0')

//Init AppWrite databases export const appwriteDatabase = new sdk.Databases(appwriteClient)

TL;DR
The user is trying to access their collections from a Node.js server using the 'node-appwrite' SDK. However, they are receiving a 'user_unauthorized' error. The error stack trace indicates that the current user is not authorized to perform the requested action. A possible solution is to check if the API key and project ID are correct and if the API key has enough scopes. Additionally, the user is advised to wrap the code in backticks for better formatting.
Drake
22 Oct, 2023, 21:17

FYI, it's best to wrap code in backticks to format a bit nicer. You can use 1 backtick for inline code (https://www.markdownguide.org/basic-syntax/#code) and 3 backticks for multiline code (https://www.markdownguide.org/extended-syntax/#syntax-highlighting.

Drake
22 Oct, 2023, 21:18

maybe the api key or project id is incorrect or the api key doesn't have enough scopes

Drake
23 Oct, 2023, 15:54
Drake
23 Oct, 2023, 15:57

Also, you have a stack trace...what line is it throwing on exactly?

And does your collection have relationships?

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