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 our Cloud Functions tutorial.
https://<REGION>.cloud.appwrite.io/v1
Create function
Create a new function. You can pass a list of permissions to allow different project users or team with access to execute the function using the client API.
Request
functionId string 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.name string requiredFunction name. Max length: 128 chars.
runtime string requiredExecution runtime.
execute array 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.
events array Events list. Maximum of 100 events are allowed.
schedule string Schedule CRON syntax.
timeout integer Function maximum execution time in seconds.
enabled boolean 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.
logging boolean When disabled, executions will exclude logs and errors, and will be slightly faster.
entrypoint string Entrypoint File. This path is relative to the "providerRootDirectory".
commands string Build Commands.
scopes array List of scopes allowed for API key auto-generated for every execution. Maximum of 100 scopes are allowed.
installationId string Appwrite Installation ID for VCS (Version Control System) deployment.
providerRepositoryId string Repository ID of the repo linked to the function.
providerBranch string Production branch for the repo linked to the function.
providerSilentMode boolean 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.
providerRootDirectory string Path to function code in the linked repo.
specification string Runtime specification for the function and builds.
Response
201 application/json
POST /functions
require 'appwrite'
include Appwrite
include Appwrite::Enums
client = Client.new
.set_endpoint('https://<REGION>.cloud.appwrite.io/v1') # Your API Endpoint
.set_project('<YOUR_PROJECT_ID>') # Your project ID
.set_key('<YOUR_API_KEY>') # Your secret API key
functions = Functions.new(client)
result = functions.create(
function_id: '<FUNCTION_ID>',
name: '<NAME>',
runtime: ::NODE_14_5,
execute: ["any"], # optional
events: [], # optional
schedule: '', # optional
timeout: 1, # optional
enabled: false, # optional
logging: false, # optional
entrypoint: '<ENTRYPOINT>', # optional
commands: '<COMMANDS>', # optional
scopes: [], # optional
installation_id: '<INSTALLATION_ID>', # optional
provider_repository_id: '<PROVIDER_REPOSITORY_ID>', # optional
provider_branch: '<PROVIDER_BRANCH>', # optional
provider_silent_mode: false, # optional
provider_root_directory: '<PROVIDER_ROOT_DIRECTORY>', # optional
specification: '' # optional
)
Get function
Get a function by its unique ID.
Request
functionId string requiredFunction ID.
Response
200 application/json
GET /functions/{functionId}
require 'appwrite'
include Appwrite
client = Client.new
.set_endpoint('https://<REGION>.cloud.appwrite.io/v1') # Your API Endpoint
.set_project('<YOUR_PROJECT_ID>') # Your project ID
.set_key('<YOUR_API_KEY>') # Your secret API key
functions = Functions.new(client)
result = functions.get(
function_id: '<FUNCTION_ID>'
)
List functions
Get a list of all the project's functions. You can use the query params to filter your results.
Request
queries array 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
search string Search term to filter your list results. Max length: 256 chars.
Response
200 application/json
GET /functions
require 'appwrite'
include Appwrite
client = Client.new
.set_endpoint('https://<REGION>.cloud.appwrite.io/v1') # Your API Endpoint
.set_project('<YOUR_PROJECT_ID>') # Your project ID
.set_key('<YOUR_API_KEY>') # Your secret API key
functions = Functions.new(client)
result = functions.list(
queries: [], # optional
search: '<SEARCH>' # optional
)
Update function
Update function by its unique ID.
Request
functionId string requiredFunction ID.
name string requiredFunction name. Max length: 128 chars.
runtime string Execution runtime.
execute array 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.
events array Events list. Maximum of 100 events are allowed.
schedule string Schedule CRON syntax.
timeout integer Maximum execution time in seconds.
enabled boolean 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.
logging boolean When disabled, executions will exclude logs and errors, and will be slightly faster.
entrypoint string Entrypoint File. This path is relative to the "providerRootDirectory".
commands string Build Commands.
scopes array List of scopes allowed for API Key auto-generated for every execution. Maximum of 100 scopes are allowed.
installationId string Appwrite Installation ID for VCS (Version Controle System) deployment.
providerRepositoryId string Repository ID of the repo linked to the function
providerBranch string Production branch for the repo linked to the function
providerSilentMode boolean 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.
providerRootDirectory string Path to function code in the linked repo.
specification string Runtime specification for the function and builds.
Response
200 application/json
PUT /functions/{functionId}
require 'appwrite'
include Appwrite
client = Client.new
.set_endpoint('https://<REGION>.cloud.appwrite.io/v1') # Your API Endpoint
.set_project('<YOUR_PROJECT_ID>') # Your project ID
.set_key('<YOUR_API_KEY>') # Your secret API key
functions = Functions.new(client)
result = functions.update(
function_id: '<FUNCTION_ID>',
name: '<NAME>',
runtime: ::NODE_14_5, # optional
execute: ["any"], # optional
events: [], # optional
schedule: '', # optional
timeout: 1, # optional
enabled: false, # optional
logging: false, # optional
entrypoint: '<ENTRYPOINT>', # optional
commands: '<COMMANDS>', # optional
scopes: [], # optional
installation_id: '<INSTALLATION_ID>', # optional
provider_repository_id: '<PROVIDER_REPOSITORY_ID>', # optional
provider_branch: '<PROVIDER_BRANCH>', # optional
provider_silent_mode: false, # optional
provider_root_directory: '<PROVIDER_ROOT_DIRECTORY>', # 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.
Request
functionId string requiredFunction ID.
deploymentId string requiredDeployment ID.
Response
200 application/json
PATCH /functions/{functionId}/deployment
require 'appwrite'
include Appwrite
client = Client.new
.set_endpoint('https://<REGION>.cloud.appwrite.io/v1') # Your API Endpoint
.set_project('<YOUR_PROJECT_ID>') # Your project ID
.set_key('<YOUR_API_KEY>') # Your secret API key
functions = Functions.new(client)
result = functions.update_function_deployment(
function_id: '<FUNCTION_ID>',
deployment_id: '<DEPLOYMENT_ID>'
)
Delete function
Delete a function by its unique ID.
Request
functionId string requiredFunction ID.
Response
204 application/json
DELETE /functions/{functionId}
require 'appwrite'
include Appwrite
client = Client.new
.set_endpoint('https://<REGION>.cloud.appwrite.io/v1') # Your API Endpoint
.set_project('<YOUR_PROJECT_ID>') # Your project ID
.set_key('<YOUR_API_KEY>') # Your secret API key
functions = Functions.new(client)
result = functions.delete(
function_id: '<FUNCTION_ID>'
)
List runtimes
Get a list of all runtimes that are currently active on your instance.
Response
200 application/json
GET /functions/runtimes
require 'appwrite'
include Appwrite
client = Client.new
.set_endpoint('https://<REGION>.cloud.appwrite.io/v1') # Your API Endpoint
.set_project('<YOUR_PROJECT_ID>') # Your project ID
.set_key('<YOUR_API_KEY>') # Your secret API key
functions = Functions.new(client)
result = functions.list_runtimes()
List specifications
List allowed function specifications for this instance.
Response
200 application/json
GET /functions/specifications
require 'appwrite'
include Appwrite
client = Client.new
.set_endpoint('https://<REGION>.cloud.appwrite.io/v1') # Your API Endpoint
.set_project('<YOUR_PROJECT_ID>') # Your project ID
.set_key('<YOUR_API_KEY>') # Your secret API key
functions = Functions.new(client)
result = functions.list_specifications()
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 the Appwrite Cloud Functions tutorial.
Use the "command" param to set the entrypoint used to execute your code.
Request
functionId string requiredFunction ID.
code string 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.
activate boolean requiredAutomatically activate the deployment when it is finished building.
entrypoint string Entrypoint File.
commands string Build Commands.
Response
202 application/json
POST /functions/{functionId}/deployments
require 'appwrite'
include Appwrite
client = Client.new
.set_endpoint('https://<REGION>.cloud.appwrite.io/v1') # Your API Endpoint
.set_project('<YOUR_PROJECT_ID>') # Your project ID
.set_key('<YOUR_API_KEY>') # Your secret API key
functions = Functions.new(client)
result = functions.create_deployment(
function_id: '<FUNCTION_ID>',
code: InputFile.from_path('dir/file.png'),
activate: false,
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.
Request
functionId string requiredFunction ID.
deploymentId string requiredDeployment ID.
buildId string Build unique ID.
Response
202 application/json
POST /functions/{functionId}/deployments/duplicate
require 'appwrite'
include Appwrite
client = Client.new
.set_endpoint('https://<REGION>.cloud.appwrite.io/v1') # Your API Endpoint
.set_project('<YOUR_PROJECT_ID>') # Your project ID
.set_key('<YOUR_API_KEY>') # Your secret API key
functions = Functions.new(client)
result = functions.create_duplicate_deployment(
function_id: '<FUNCTION_ID>',
deployment_id: '<DEPLOYMENT_ID>',
build_id: '<BUILD_ID>' # optional
)
Create template deployment
Create a deployment based on a template.
Use this endpoint with combination of listTemplates to find the template details.
Request
functionId string requiredFunction ID.
repository string requiredRepository name of the template.
owner string requiredThe name of the owner of the template.
rootDirectory string requiredPath to function code in the template repo.
version string requiredVersion (tag) for the repo linked to the function template.
activate boolean Automatically activate the deployment when it is finished building.
Response
202 application/json
POST /functions/{functionId}/deployments/template
require 'appwrite'
include Appwrite
client = Client.new
.set_endpoint('https://<REGION>.cloud.appwrite.io/v1') # Your API Endpoint
.set_project('<YOUR_PROJECT_ID>') # Your project ID
.set_key('<YOUR_API_KEY>') # Your secret API key
functions = Functions.new(client)
result = functions.create_template_deployment(
function_id: '<FUNCTION_ID>',
repository: '<REPOSITORY>',
owner: '<OWNER>',
root_directory: '<ROOT_DIRECTORY>',
version: '<VERSION>',
activate: false # 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
functionId string requiredFunction ID.
type string requiredType of reference passed. Allowed values are: branch, commit
reference string requiredVCS reference to create deployment from. Depending on type this can be: branch name, commit hash
activate boolean Automatically activate the deployment when it is finished building.
Response
202 application/json
POST /functions/{functionId}/deployments/vcs
require 'appwrite'
include Appwrite
include Appwrite::Enums
client = Client.new
.set_endpoint('https://<REGION>.cloud.appwrite.io/v1') # Your API Endpoint
.set_project('<YOUR_PROJECT_ID>') # Your project ID
.set_key('<YOUR_API_KEY>') # Your secret API key
functions = Functions.new(client)
result = functions.create_vcs_deployment(
function_id: '<FUNCTION_ID>',
type: VCSDeploymentType::BRANCH,
reference: '<REFERENCE>',
activate: false # optional
)
Get deployment
Get a function deployment by its unique ID.
Request
functionId string requiredFunction ID.
deploymentId string requiredDeployment ID.
Response
200 application/json
GET /functions/{functionId}/deployments/{deploymentId}
require 'appwrite'
include Appwrite
client = Client.new
.set_endpoint('https://<REGION>.cloud.appwrite.io/v1') # Your API Endpoint
.set_project('<YOUR_PROJECT_ID>') # Your project ID
.set_key('<YOUR_API_KEY>') # Your secret API key
functions = Functions.new(client)
result = functions.get_deployment(
function_id: '<FUNCTION_ID>',
deployment_id: '<DEPLOYMENT_ID>'
)
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.
Request
functionId string requiredFunction ID.
deploymentId string requiredDeployment ID.
type string Deployment file to download. Can be: "source", "output".
Response
200 application/json
GET /functions/{functionId}/deployments/{deploymentId}/download
require 'appwrite'
include Appwrite
client = Client.new
.set_endpoint('https://<REGION>.cloud.appwrite.io/v1') # Your API Endpoint
.set_project('<YOUR_PROJECT_ID>') # Your project ID
.set_key('<YOUR_API_KEY>') # Your secret API key
functions = Functions.new(client)
result = functions.get_deployment_download(
function_id: '<FUNCTION_ID>',
deployment_id: '<DEPLOYMENT_ID>',
type: DeploymentDownloadType::SOURCE # optional
)
List deployments
Get a list of all the function's code deployments. You can use the query params to filter your results.
Request
functionId string requiredFunction ID.
queries array 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
search string Search term to filter your list results. Max length: 256 chars.
Response
200 application/json
GET /functions/{functionId}/deployments
require 'appwrite'
include Appwrite
client = Client.new
.set_endpoint('https://<REGION>.cloud.appwrite.io/v1') # Your API Endpoint
.set_project('<YOUR_PROJECT_ID>') # Your project ID
.set_key('<YOUR_API_KEY>') # Your secret API key
functions = Functions.new(client)
result = functions.list_deployments(
function_id: '<FUNCTION_ID>',
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.
Request
functionId string requiredFunction ID.
deploymentId string requiredDeployment ID.
Response
200 application/json
PATCH /functions/{functionId}/deployments/{deploymentId}/status
require 'appwrite'
include Appwrite
client = Client.new
.set_endpoint('https://<REGION>.cloud.appwrite.io/v1') # Your API Endpoint
.set_project('<YOUR_PROJECT_ID>') # Your project ID
.set_key('<YOUR_API_KEY>') # Your secret API key
functions = Functions.new(client)
result = functions.update_deployment_status(
function_id: '<FUNCTION_ID>',
deployment_id: '<DEPLOYMENT_ID>'
)
Delete deployment
Delete a code deployment by its unique ID.
Request
functionId string requiredFunction ID.
deploymentId string requiredDeployment ID.
Response
204 application/json
DELETE /functions/{functionId}/deployments/{deploymentId}
require 'appwrite'
include Appwrite
client = Client.new
.set_endpoint('https://<REGION>.cloud.appwrite.io/v1') # Your API Endpoint
.set_project('<YOUR_PROJECT_ID>') # Your project ID
.set_key('<YOUR_API_KEY>') # Your secret API key
functions = Functions.new(client)
result = functions.delete_deployment(
function_id: '<FUNCTION_ID>',
deployment_id: '<DEPLOYMENT_ID>'
)
Create execution
Trigger a function execution. The returned object will return you the current execution status. You can ping the Get Execution
endpoint to get updates on the current execution status. Once this endpoint is called, your function execution process will start asynchronously.
Request
functionId string requiredFunction ID.
body string HTTP body of execution. Default value is empty string.
async boolean Execute code in the background. Default value is false.
path string HTTP path of execution. Path can include query params. Default value is /
method string HTTP method of execution. Default value is GET.
headers string HTTP headers of execution. Defaults to empty.
scheduledAt string Scheduled execution time in ISO 8601 format. DateTime value must be in future with precision in minutes.
Response
201 application/json
POST /functions/{functionId}/executions
require 'appwrite'
include Appwrite
client = Client.new
.set_endpoint('https://<REGION>.cloud.appwrite.io/v1') # Your API Endpoint
.set_project('<YOUR_PROJECT_ID>') # Your project ID
.set_session('') # The user session to authenticate with
functions = Functions.new(client)
result = functions.create_execution(
function_id: '<FUNCTION_ID>',
body: '<BODY>', # optional
async: false, # optional
path: '<PATH>', # optional
method: ExecutionMethod::GET, # optional
headers: {}, # optional
scheduled_at: '' # optional
)
Get execution
Get a function execution log by its unique ID.
Request
functionId string requiredFunction ID.
executionId string requiredExecution ID.
Response
200 application/json
GET /functions/{functionId}/executions/{executionId}
require 'appwrite'
include Appwrite
client = Client.new
.set_endpoint('https://<REGION>.cloud.appwrite.io/v1') # Your API Endpoint
.set_project('<YOUR_PROJECT_ID>') # Your project ID
.set_session('') # The user session to authenticate with
functions = Functions.new(client)
result = functions.get_execution(
function_id: '<FUNCTION_ID>',
execution_id: '<EXECUTION_ID>'
)
List executions
Get a list of all the current user function execution logs. You can use the query params to filter your results.
Request
functionId string requiredFunction ID.
queries array 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
Response
200 application/json
GET /functions/{functionId}/executions
require 'appwrite'
include Appwrite
client = Client.new
.set_endpoint('https://<REGION>.cloud.appwrite.io/v1') # Your API Endpoint
.set_project('<YOUR_PROJECT_ID>') # Your project ID
.set_session('') # The user session to authenticate with
functions = Functions.new(client)
result = functions.list_executions(
function_id: '<FUNCTION_ID>',
queries: [] # optional
)
Delete execution
Delete a function execution by its unique ID.
Request
functionId string requiredFunction ID.
executionId string requiredExecution ID.
Response
204 application/json
DELETE /functions/{functionId}/executions/{executionId}
require 'appwrite'
include Appwrite
client = Client.new
.set_endpoint('https://<REGION>.cloud.appwrite.io/v1') # Your API Endpoint
.set_project('<YOUR_PROJECT_ID>') # Your project ID
.set_key('<YOUR_API_KEY>') # Your secret API key
functions = Functions.new(client)
result = functions.delete_execution(
function_id: '<FUNCTION_ID>',
execution_id: '<EXECUTION_ID>'
)
Create variable
Create a new function environment variable. These variables can be accessed in the function at runtime as environment variables.
Request
functionId string requiredFunction unique ID.
key string requiredVariable key. Max length: 255 chars.
value string requiredVariable value. Max length: 8192 chars.
secret boolean Secret variables can be updated or deleted, but only functions can read them during build and runtime.
Response
201 application/json
POST /functions/{functionId}/variables
require 'appwrite'
include Appwrite
client = Client.new
.set_endpoint('https://<REGION>.cloud.appwrite.io/v1') # Your API Endpoint
.set_project('<YOUR_PROJECT_ID>') # Your project ID
.set_key('<YOUR_API_KEY>') # Your secret API key
functions = Functions.new(client)
result = functions.create_variable(
function_id: '<FUNCTION_ID>',
key: '<KEY>',
value: '<VALUE>',
secret: false # optional
)
Get variable
Get a variable by its unique ID.
Request
functionId string requiredFunction unique ID.
variableId string requiredVariable unique ID.
Response
200 application/json
GET /functions/{functionId}/variables/{variableId}
require 'appwrite'
include Appwrite
client = Client.new
.set_endpoint('https://<REGION>.cloud.appwrite.io/v1') # Your API Endpoint
.set_project('<YOUR_PROJECT_ID>') # Your project ID
.set_key('<YOUR_API_KEY>') # Your secret API key
functions = Functions.new(client)
result = functions.get_variable(
function_id: '<FUNCTION_ID>',
variable_id: '<VARIABLE_ID>'
)
List variables
Get a list of all variables of a specific function.
Request
functionId string requiredFunction unique ID.
Response
200 application/json
GET /functions/{functionId}/variables
require 'appwrite'
include Appwrite
client = Client.new
.set_endpoint('https://<REGION>.cloud.appwrite.io/v1') # Your API Endpoint
.set_project('<YOUR_PROJECT_ID>') # Your project ID
.set_key('<YOUR_API_KEY>') # Your secret API key
functions = Functions.new(client)
result = functions.list_variables(
function_id: '<FUNCTION_ID>'
)
Update variable
Update variable by its unique ID.
Request
functionId string requiredFunction unique ID.
variableId string requiredVariable unique ID.
key string requiredVariable key. Max length: 255 chars.
value string Variable value. Max length: 8192 chars.
secret boolean Secret variables can be updated or deleted, but only functions can read them during build and runtime.
Response
200 application/json
PUT /functions/{functionId}/variables/{variableId}
require 'appwrite'
include Appwrite
client = Client.new
.set_endpoint('https://<REGION>.cloud.appwrite.io/v1') # Your API Endpoint
.set_project('<YOUR_PROJECT_ID>') # Your project ID
.set_key('<YOUR_API_KEY>') # Your secret API key
functions = Functions.new(client)
result = functions.update_variable(
function_id: '<FUNCTION_ID>',
variable_id: '<VARIABLE_ID>',
key: '<KEY>',
value: '<VALUE>', # optional
secret: false # optional
)
Delete variable
Delete a variable by its unique ID.
Request
functionId string requiredFunction unique ID.
variableId string requiredVariable unique ID.
Response
204 application/json
DELETE /functions/{functionId}/variables/{variableId}
require 'appwrite'
include Appwrite
client = Client.new
.set_endpoint('https://<REGION>.cloud.appwrite.io/v1') # Your API Endpoint
.set_project('<YOUR_PROJECT_ID>') # Your project ID
.set_key('<YOUR_API_KEY>') # Your secret API key
functions = Functions.new(client)
result = functions.delete_variable(
function_id: '<FUNCTION_ID>',
variable_id: '<VARIABLE_ID>'
)