Skip to content
Back

Listing all function deployments from a function always causes an error

  • 0
  • Cloud
maru
22 Aug, 2025, 00:27

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)

TypeScript
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();
};
TL;DR
Developers are encountering an error when listing function deployments, even though the function has all necessary scopes assigned. The provided code aims to delete old deployments to free up storage space. The error indicates a missing 'functions.read' scope despite all scopes being assigned during testing. The solution might lie in investigating why the 'functions.read' scope is seemingly missing.
maru
22 Aug, 2025, 00:27

However, when I try to execute the function, I always get this error:

TypeScript
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...

maru
22 Aug, 2025, 00:47

It seems to already fail at serverFunctions.list() , since there are no other logs

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