Functions
The Functions service allows you to create custom behaviour that can be triggered by any supported Appwrite system events or by a predefined schedule.
Appwrite Cloud Functions lets you automatically run backend code in response to events triggered by Appwrite or by setting it to be executed in a predefined schedule. Your code is stored in a secure way on your Appwrite instance and is executed in an isolated environment.
You can learn more by following ourCloud Functions tutorial.
https://<REGION>.cloud.appwrite.io/v1
Create function
Create a new function. You can pass a list ofpermissions to allow different project users or team with access to execute the function using the client API.
Request
functionIdstring requiredFunction ID. Choose a custom ID or generate a random ID with
ID.unique()
. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.namestring requiredFunction name. Max length: 128 chars.
runtimestring requiredExecution runtime.
executearray An array of role strings with execution permissions. By default no user is granted with any execute permissions.learn more about roles. Maximum of 100 roles are allowed, each 64 characters long.
eventsarray Events list. Maximum of 100 events are allowed.
schedulestring Schedule CRON syntax.
timeoutinteger Function maximum execution time in seconds.
enabledboolean Is function enabled? When set to 'disabled', users cannot access the function but Server SDKs with and API key can still access the function. No data is lost when this is toggled.
loggingboolean When disabled, executions will exclude logs and errors, and will be slightly faster.
entrypointstring Entrypoint File. This path is relative to the "providerRootDirectory".
commandsstring Build Commands.
scopesarray List of scopes allowed for API key auto-generated for every execution. Maximum of 100 scopes are allowed.
installationIdstring Appwrite Installation ID for VCS (Version Control System) deployment.
providerRepositoryIdstring Repository ID of the repo linked to the function.
providerBranchstring Production branch for the repo linked to the function.
providerSilentModeboolean Is the VCS (Version Control System) connection in silent mode for the repo linked to the function? In silent mode, comments will not be made on commits and pull requests.
providerRootDirectorystring Path to function code in the linked repo.
specificationstring Runtime specification for the function and builds.
POST /functions
const sdk =require('node-appwrite');const client =new sdk.Client() .setEndpoint('https://<REGION>.cloud.appwrite.io/v1')// Your API Endpoint .setProject('<YOUR_PROJECT_ID>')// Your project ID .setKey('<YOUR_API_KEY>');// Your secret API keyconst functions =new sdk.Functions(client);const result =await functions.create('<FUNCTION_ID>',// functionId'<NAME>',// name sdk..Node145,// runtime ["any"],// execute (optional) [],// events (optional)'',// schedule (optional)1,// timeout (optional)false,// enabled (optional)false,// logging (optional)'<ENTRYPOINT>',// entrypoint (optional)'<COMMANDS>',// commands (optional) [],// scopes (optional)'<INSTALLATION_ID>',// installationId (optional)'<PROVIDER_REPOSITORY_ID>',// providerRepositoryId (optional)'<PROVIDER_BRANCH>',// providerBranch (optional)false,// providerSilentMode (optional)'<PROVIDER_ROOT_DIRECTORY>',// providerRootDirectory (optional)''// specification (optional));
GET /functions/{functionId}
const sdk =require('node-appwrite');const client =new sdk.Client() .setEndpoint('https://<REGION>.cloud.appwrite.io/v1')// Your API Endpoint .setProject('<YOUR_PROJECT_ID>')// Your project ID .setKey('<YOUR_API_KEY>');// Your secret API keyconst functions =new sdk.Functions(client);const result =await functions.get('<FUNCTION_ID>'// functionId);
List functions
Get a list of all the project's functions. You can use the query params to filter your results.
Request
queriesarray Array of query strings generated using the Query class provided by the SDK.Learn more about queries. Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: name, enabled, runtime, deploymentId, schedule, scheduleNext, schedulePrevious, timeout, entrypoint, commands, installationId
searchstring Search term to filter your list results. Max length: 256 chars.
GET /functions
const sdk =require('node-appwrite');const client =new sdk.Client() .setEndpoint('https://<REGION>.cloud.appwrite.io/v1')// Your API Endpoint .setProject('<YOUR_PROJECT_ID>')// Your project ID .setKey('<YOUR_API_KEY>');// Your secret API keyconst functions =new sdk.Functions(client);const result =await functions.list( [],// queries (optional)'<SEARCH>'// search (optional));
Update function
Update function by its unique ID.
Request
functionIdstring requiredFunction ID.
namestring requiredFunction name. Max length: 128 chars.
runtimestring Execution runtime.
executearray An array of role strings with execution permissions. By default no user is granted with any execute permissions.learn more about roles. Maximum of 100 roles are allowed, each 64 characters long.
eventsarray Events list. Maximum of 100 events are allowed.
schedulestring Schedule CRON syntax.
timeoutinteger Maximum execution time in seconds.
enabledboolean Is function enabled? When set to 'disabled', users cannot access the function but Server SDKs with and API key can still access the function. No data is lost when this is toggled.
loggingboolean When disabled, executions will exclude logs and errors, and will be slightly faster.
entrypointstring Entrypoint File. This path is relative to the "providerRootDirectory".
commandsstring Build Commands.
scopesarray List of scopes allowed for API Key auto-generated for every execution. Maximum of 100 scopes are allowed.
installationIdstring Appwrite Installation ID for VCS (Version Controle System) deployment.
providerRepositoryIdstring Repository ID of the repo linked to the function
providerBranchstring Production branch for the repo linked to the function
providerSilentModeboolean Is the VCS (Version Control System) connection in silent mode for the repo linked to the function? In silent mode, comments will not be made on commits and pull requests.
providerRootDirectorystring Path to function code in the linked repo.
specificationstring Runtime specification for the function and builds.
PUT /functions/{functionId}
const sdk =require('node-appwrite');const client =new sdk.Client() .setEndpoint('https://<REGION>.cloud.appwrite.io/v1')// Your API Endpoint .setProject('<YOUR_PROJECT_ID>')// Your project ID .setKey('<YOUR_API_KEY>');// Your secret API keyconst functions =new sdk.Functions(client);const result =await functions.update('<FUNCTION_ID>',// functionId'<NAME>',// name sdk..Node145,// runtime (optional) ["any"],// execute (optional) [],// events (optional)'',// schedule (optional)1,// timeout (optional)false,// enabled (optional)false,// logging (optional)'<ENTRYPOINT>',// entrypoint (optional)'<COMMANDS>',// commands (optional) [],// scopes (optional)'<INSTALLATION_ID>',// installationId (optional)'<PROVIDER_REPOSITORY_ID>',// providerRepositoryId (optional)'<PROVIDER_BRANCH>',// providerBranch (optional)false,// providerSilentMode (optional)'<PROVIDER_ROOT_DIRECTORY>',// providerRootDirectory (optional)''// specification (optional));
Update function's deployment
Update the function active deployment. Use this endpoint to switch the code deployment that should be used when visitor opens your function.
PATCH /functions/{functionId}/deployment
const sdk =require('node-appwrite');const client =new sdk.Client() .setEndpoint('https://<REGION>.cloud.appwrite.io/v1')// Your API Endpoint .setProject('<YOUR_PROJECT_ID>')// Your project ID .setKey('<YOUR_API_KEY>');// Your secret API keyconst functions =new sdk.Functions(client);const result =await functions.updateFunctionDeployment('<FUNCTION_ID>',// functionId'<DEPLOYMENT_ID>'// deploymentId);
DELETE /functions/{functionId}
const sdk =require('node-appwrite');const client =new sdk.Client() .setEndpoint('https://<REGION>.cloud.appwrite.io/v1')// Your API Endpoint .setProject('<YOUR_PROJECT_ID>')// Your project ID .setKey('<YOUR_API_KEY>');// Your secret API keyconst functions =new sdk.Functions(client);const result =await functions.delete('<FUNCTION_ID>'// functionId);
GET /functions/runtimes
const sdk =require('node-appwrite');const client =new sdk.Client() .setEndpoint('https://<REGION>.cloud.appwrite.io/v1')// Your API Endpoint .setProject('<YOUR_PROJECT_ID>')// Your project ID .setKey('<YOUR_API_KEY>');// Your secret API keyconst functions =new sdk.Functions(client);const result =await functions.listRuntimes();
GET /functions/specifications
const sdk =require('node-appwrite');const client =new sdk.Client() .setEndpoint('https://<REGION>.cloud.appwrite.io/v1')// Your API Endpoint .setProject('<YOUR_PROJECT_ID>')// Your project ID .setKey('<YOUR_API_KEY>');// Your secret API keyconst functions =new sdk.Functions(client);const result =await functions.listSpecifications();
Create deployment
Create a new function code deployment. Use this endpoint to upload a new version of your code function. To execute your newly uploaded code, you'll need to update the function's deployment to use your new deployment UID.
This endpoint accepts a tar.gz file compressed with your code. Make sure to include any dependencies your code has within the compressed file. You can learn more about code packaging in theAppwrite Cloud Functions tutorial.
Use the "command" param to set the entrypoint used to execute your code.
Request
functionIdstring requiredFunction ID.
codestring requiredGzip file with your code package. When used with the Appwrite CLI, pass the path to your code directory, and the CLI will automatically package your code. Use a path that is within the current directory.
activateboolean requiredAutomatically activate the deployment when it is finished building.
entrypointstring Entrypoint File.
commandsstring Build Commands.
POST /functions/{functionId}/deployments
const sdk =require('node-appwrite');const fs =require('fs');const client =new sdk.Client() .setEndpoint('https://<REGION>.cloud.appwrite.io/v1')// Your API Endpoint .setProject('<YOUR_PROJECT_ID>')// Your project ID .setKey('<YOUR_API_KEY>');// Your secret API keyconst functions =new sdk.Functions(client);const result =await functions.createDeployment('<FUNCTION_ID>',// functionIdInputFile.fromPath('/path/to/file','filename'),// codefalse,// activate'<ENTRYPOINT>',// entrypoint (optional)'<COMMANDS>'// commands (optional));
Create duplicate deployment
Create a new build for an existing function deployment. This endpoint allows you to rebuild a deployment with the updated function configuration, including its entrypoint and build commands if they have been modified. The build process will be queued and executed asynchronously. The original deployment's code will be preserved and used for the new build.
POST /functions/{functionId}/deployments/duplicate
const sdk =require('node-appwrite');const client =new sdk.Client() .setEndpoint('https://<REGION>.cloud.appwrite.io/v1')// Your API Endpoint .setProject('<YOUR_PROJECT_ID>')// Your project ID .setKey('<YOUR_API_KEY>');// Your secret API keyconst functions =new sdk.Functions(client);const result =await functions.createDuplicateDeployment('<FUNCTION_ID>',// functionId'<DEPLOYMENT_ID>',// deploymentId'<BUILD_ID>'// buildId (optional));
Create template deployment
Create a deployment based on a template.
Use this endpoint with combination oflistTemplates to find the template details.
Request
functionIdstring requiredFunction ID.
repositorystring requiredRepository name of the template.
ownerstring requiredThe name of the owner of the template.
rootDirectorystring requiredPath to function code in the template repo.
versionstring requiredVersion (tag) for the repo linked to the function template.
activateboolean Automatically activate the deployment when it is finished building.
POST /functions/{functionId}/deployments/template
const sdk =require('node-appwrite');const client =new sdk.Client() .setEndpoint('https://<REGION>.cloud.appwrite.io/v1')// Your API Endpoint .setProject('<YOUR_PROJECT_ID>')// Your project ID .setKey('<YOUR_API_KEY>');// Your secret API keyconst functions =new sdk.Functions(client);const result =await functions.createTemplateDeployment('<FUNCTION_ID>',// functionId'<REPOSITORY>',// repository'<OWNER>',// owner'<ROOT_DIRECTORY>',// rootDirectory'<VERSION>',// versionfalse// activate (optional));
Create VCS deployment
Create a deployment when a function is connected to VCS.
This endpoint lets you create deployment from a branch, commit, or a tag.
Request
functionIdstring requiredFunction ID.
typestring requiredType of reference passed. Allowed values are: branch, commit
referencestring requiredVCS reference to create deployment from. Depending on type this can be: branch name, commit hash
activateboolean Automatically activate the deployment when it is finished building.
POST /functions/{functionId}/deployments/vcs
const sdk =require('node-appwrite');const client =new sdk.Client() .setEndpoint('https://<REGION>.cloud.appwrite.io/v1')// Your API Endpoint .setProject('<YOUR_PROJECT_ID>')// Your project ID .setKey('<YOUR_API_KEY>');// Your secret API keyconst functions =new sdk.Functions(client);const result =await functions.createVcsDeployment('<FUNCTION_ID>',// functionId sdk.VCSDeploymentType.Branch,// type'<REFERENCE>',// referencefalse// activate (optional));
GET /functions/{functionId}/deployments/{deploymentId}
const sdk =require('node-appwrite');const client =new sdk.Client() .setEndpoint('https://<REGION>.cloud.appwrite.io/v1')// Your API Endpoint .setProject('<YOUR_PROJECT_ID>')// Your project ID .setKey('<YOUR_API_KEY>');// Your secret API keyconst functions =new sdk.Functions(client);const result =await functions.getDeployment('<FUNCTION_ID>',// functionId'<DEPLOYMENT_ID>'// deploymentId);
Get deployment download
Get a function deployment content by its unique ID. The endpoint response return with a 'Content-Disposition: attachment' header that tells the browser to start downloading the file to user downloads directory.
Response
GET /functions/{functionId}/deployments/{deploymentId}/download
const sdk =require('node-appwrite');const client =new sdk.Client() .setEndpoint('https://<REGION>.cloud.appwrite.io/v1')// Your API Endpoint .setProject('<YOUR_PROJECT_ID>')// Your project ID .setKey('<YOUR_API_KEY>');// Your secret API keyconst functions =new sdk.Functions(client);const result =await functions.getDeploymentDownload('<FUNCTION_ID>',// functionId'<DEPLOYMENT_ID>',// deploymentId sdk.DeploymentDownloadType.Source// type (optional));
List deployments
Get a list of all the function's code deployments. You can use the query params to filter your results.
Request
functionIdstring requiredFunction ID.
queriesarray Array of query strings generated using the Query class provided by the SDK.Learn more about queries. Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: buildSize, sourceSize, totalSize, buildDuration, status, activate, type
searchstring Search term to filter your list results. Max length: 256 chars.
GET /functions/{functionId}/deployments
const sdk =require('node-appwrite');const client =new sdk.Client() .setEndpoint('https://<REGION>.cloud.appwrite.io/v1')// Your API Endpoint .setProject('<YOUR_PROJECT_ID>')// Your project ID .setKey('<YOUR_API_KEY>');// Your secret API keyconst functions =new sdk.Functions(client);const result =await functions.listDeployments('<FUNCTION_ID>',// functionId [],// queries (optional)'<SEARCH>'// search (optional));
Update deployment status
Cancel an ongoing function deployment build. If the build is already in progress, it will be stopped and marked as canceled. If the build hasn't started yet, it will be marked as canceled without executing. You cannot cancel builds that have already completed (status 'ready') or failed. The response includes the final build status and details.
PATCH /functions/{functionId}/deployments/{deploymentId}/status
const sdk =require('node-appwrite');const client =new sdk.Client() .setEndpoint('https://<REGION>.cloud.appwrite.io/v1')// Your API Endpoint .setProject('<YOUR_PROJECT_ID>')// Your project ID .setKey('<YOUR_API_KEY>');// Your secret API keyconst functions =new sdk.Functions(client);const result =await functions.updateDeploymentStatus('<FUNCTION_ID>',// functionId'<DEPLOYMENT_ID>'// deploymentId);
DELETE /functions/{functionId}/deployments/{deploymentId}
const sdk =require('node-appwrite');const client =new sdk.Client() .setEndpoint('https://<REGION>.cloud.appwrite.io/v1')// Your API Endpoint .setProject('<YOUR_PROJECT_ID>')// Your project ID .setKey('<YOUR_API_KEY>');// Your secret API keyconst functions =new sdk.Functions(client);const result =await functions.deleteDeployment('<FUNCTION_ID>',// functionId'<DEPLOYMENT_ID>'// deploymentId);
Create execution
Trigger a function execution. The returned object will return you the current execution status. You can ping theGet Execution
endpoint to get updates on the current execution status. Once this endpoint is called, your function execution process will start asynchronously.
Request
functionIdstring requiredFunction ID.
bodystring HTTP body of execution. Default value is empty string.
asyncboolean Execute code in the background. Default value is false.
pathstring HTTP path of execution. Path can include query params. Default value is /
methodstring HTTP method of execution. Default value is GET.
headersstring HTTP headers of execution. Defaults to empty.
scheduledAtstring Scheduled execution time inISO 8601 format. DateTime value must be in future with precision in minutes.
Response
POST /functions/{functionId}/executions
const sdk =require('node-appwrite');const client =new sdk.Client() .setEndpoint('https://<REGION>.cloud.appwrite.io/v1')// Your API Endpoint .setProject('<YOUR_PROJECT_ID>')// Your project ID .setSession('');// The user session to authenticate withconst functions =new sdk.Functions(client);const result =await functions.createExecution('<FUNCTION_ID>',// functionId'<BODY>',// body (optional)false,// async (optional)'<PATH>',// path (optional) sdk.ExecutionMethod.GET,// method (optional) {},// headers (optional)''// scheduledAt (optional));
GET /functions/{functionId}/executions/{executionId}
const sdk =require('node-appwrite');const client =new sdk.Client() .setEndpoint('https://<REGION>.cloud.appwrite.io/v1')// Your API Endpoint .setProject('<YOUR_PROJECT_ID>')// Your project ID .setSession('');// The user session to authenticate withconst functions =new sdk.Functions(client);const result =await functions.getExecution('<FUNCTION_ID>',// functionId'<EXECUTION_ID>'// executionId);
List executions
Get a list of all the current user function execution logs. You can use the query params to filter your results.
Request
functionIdstring requiredFunction ID.
queriesarray Array of query strings generated using the Query class provided by the SDK.Learn more about queries. Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: trigger, status, responseStatusCode, duration, requestMethod, requestPath, deploymentId
GET /functions/{functionId}/executions
const sdk =require('node-appwrite');const client =new sdk.Client() .setEndpoint('https://<REGION>.cloud.appwrite.io/v1')// Your API Endpoint .setProject('<YOUR_PROJECT_ID>')// Your project ID .setSession('');// The user session to authenticate withconst functions =new sdk.Functions(client);const result =await functions.listExecutions('<FUNCTION_ID>',// functionId []// queries (optional));
DELETE /functions/{functionId}/executions/{executionId}
const sdk =require('node-appwrite');const client =new sdk.Client() .setEndpoint('https://<REGION>.cloud.appwrite.io/v1')// Your API Endpoint .setProject('<YOUR_PROJECT_ID>')// Your project ID .setKey('<YOUR_API_KEY>');// Your secret API keyconst functions =new sdk.Functions(client);const result =await functions.deleteExecution('<FUNCTION_ID>',// functionId'<EXECUTION_ID>'// executionId);
Create variable
Create a new function environment variable. These variables can be accessed in the function at runtime as environment variables.
POST /functions/{functionId}/variables
const sdk =require('node-appwrite');const client =new sdk.Client() .setEndpoint('https://<REGION>.cloud.appwrite.io/v1')// Your API Endpoint .setProject('<YOUR_PROJECT_ID>')// Your project ID .setKey('<YOUR_API_KEY>');// Your secret API keyconst functions =new sdk.Functions(client);const result =await functions.createVariable('<FUNCTION_ID>',// functionId'<KEY>',// key'<VALUE>',// valuefalse// secret (optional));
GET /functions/{functionId}/variables/{variableId}
const sdk =require('node-appwrite');const client =new sdk.Client() .setEndpoint('https://<REGION>.cloud.appwrite.io/v1')// Your API Endpoint .setProject('<YOUR_PROJECT_ID>')// Your project ID .setKey('<YOUR_API_KEY>');// Your secret API keyconst functions =new sdk.Functions(client);const result =await functions.getVariable('<FUNCTION_ID>',// functionId'<VARIABLE_ID>'// variableId);
GET /functions/{functionId}/variables
const sdk =require('node-appwrite');const client =new sdk.Client() .setEndpoint('https://<REGION>.cloud.appwrite.io/v1')// Your API Endpoint .setProject('<YOUR_PROJECT_ID>')// Your project ID .setKey('<YOUR_API_KEY>');// Your secret API keyconst functions =new sdk.Functions(client);const result =await functions.listVariables('<FUNCTION_ID>'// functionId);
Update variable
Update variable by its unique ID.
Request
functionIdstring requiredFunction unique ID.
variableIdstring requiredVariable unique ID.
keystring requiredVariable key. Max length: 255 chars.
valuestring Variable value. Max length: 8192 chars.
secretboolean Secret variables can be updated or deleted, but only functions can read them during build and runtime.
PUT /functions/{functionId}/variables/{variableId}
const sdk =require('node-appwrite');const client =new sdk.Client() .setEndpoint('https://<REGION>.cloud.appwrite.io/v1')// Your API Endpoint .setProject('<YOUR_PROJECT_ID>')// Your project ID .setKey('<YOUR_API_KEY>');// Your secret API keyconst functions =new sdk.Functions(client);const result =await functions.updateVariable('<FUNCTION_ID>',// functionId'<VARIABLE_ID>',// variableId'<KEY>',// key'<VALUE>',// value (optional)false// secret (optional));
DELETE /functions/{functionId}/variables/{variableId}
const sdk =require('node-appwrite');const client =new sdk.Client() .setEndpoint('https://<REGION>.cloud.appwrite.io/v1')// Your API Endpoint .setProject('<YOUR_PROJECT_ID>')// Your project ID .setKey('<YOUR_API_KEY>');// Your secret API keyconst functions =new sdk.Functions(client);const result =await functions.deleteVariable('<FUNCTION_ID>',// functionId'<VARIABLE_ID>'// variableId);
On This Page
functions
runtimes
deployments
executions
variables