
I have a function with the following code. Its purpose is to delete old deployments and win back storage capacity (since there's no option in the Console that I know of... please point me towards it if there is one <3)
import {serverFunctions} from '#/functions/appwriteClient.ts';
import type {IFunctionContext} from '#/functions/models.ts';
import {Query} from 'node-appwrite';
export default async ({res}: IFunctionContext) => {
const functions = await serverFunctions.list();
const deletionPromises: Promise<object>[] = [];
console.log(`Found ${functions.total} functions. Deleting old deployments...`);
for (const function_ of functions.functions) {
const deploymentList = await serverFunctions.listDeployments(function_.$id, [Query.equal('activate', false)]);
const deletableDeployments = deploymentList.deployments
.map((deployment) => ({...deployment, $createdAt: new Date(deployment.$createdAt)}))
.sort((a, b) => {
const aSuccessful = a.status !== 'failed' ? 1 : 0;
const bSuccessful = b.status !== 'failed' ? 1 : 0;
if (!aSuccessful || !bSuccessful) {
return bSuccessful - aSuccessful;
}
return b.$createdAt.getTime() - a.$createdAt.getTime();
});
for (const deployment of deletableDeployments.slice(3)) {
console.log(`Deleting deployment ${deployment.$id} for function ${function_.$id}`);
deletionPromises.push(serverFunctions.deleteDeployment(function_.$id, deployment.$id));
}
}
await Promise.all(deletionPromises);
return res.empty();
};

However, when I try to execute the function, I always get this error:
AppwriteException: app.xxx@service.cloud.appwrite.io (role: applications) missing scope (functions.read)
at new AppwriteException (/usr/local/server/src/function/functions/node_modules/node-appwrite/dist/client.mjs:8:5)
at <anonymous> (/usr/local/server/src/function/functions/node_modules/node-appwrite/dist/client.mjs:294:17)
at processTicksAndRejections (:12:39)
The thing is... the function has that scope. In fact, I gave it all scopes just to test if something's missing...

It seems to already fail at serverFunctions.list()
, since there are no other logs
Recommended threads
- Function deployments stuck on waiting
Project ID: **orteos** Function ID: ** crawl_worker** Deployment ID: ** 68a8a8cc668c72293b33** Theres multiple deployments waiting in line
- Realtime not working
Hi! I'm using Appwrite cloud for my flutter project and realtime. However, today I've been having some weird problem with realtime where events aren't always be...
- Is there migration script generation lik...
Having standards migration script is helpful. For example something like same script to apply for multiple DB - each DB for one tenant
