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 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 entry point used to execute your code.
Request
functionId string requiredFunction ID.
entrypoint string requiredEntrypoint File.
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.
Response
201 application/json
POST /functions/{functionId}/deployments
from appwrite.client import Client
from appwrite.input_file import InputFile
from appwrite.services.functions import Functions
client = Client()
(client
.set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint
.set_project('5df5acd0d48c2') # Your project ID
.set_key('919c2d18fb5d4...a2ae413da83346ad2') # Your secret API key
)
functions = Functions(client)
result = functions.create_deployment('[FUNCTION_ID]', '[ENTRYPOINT]', InputFile.from_path('file.png'), False)
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.
data string String of custom data to send to function.
async boolean Execute code asynchronously. Default value is true.
Response
201 application/json
Rate limits
This endpoint is not limited when using Server SDKs with API keys. If you are using SSR with
setSession
, these rate limits will still apply. Learn more about SSR rate limits.The limit is applied for each unique limit key.
Time frameAttemptsKey1 minutes 60 requests URL + IP
POST /functions/{functionId}/executions
from appwrite.client import Client
from appwrite.services.functions import Functions
client = Client()
(client
.set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint
.set_project('5df5acd0d48c2') # Your project ID
.set_key('919c2d18fb5d4...a2ae413da83346ad2') # Your secret API key
)
functions = Functions(client)
result = functions.create_execution('[FUNCTION_ID]')
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 your own unique ID or pass the string "unique()" to auto generate it. 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.
execute array requiredAn array of strings with execution permissions. By default no user is granted with any execute permissions. learn more about permissions and get a full list of available permissions. Maximum of 100 scopes are allowed, each 64 characters long.
runtime string requiredExecution runtime.
vars object Key-value JSON object that will be passed to the function as environment variables.
events array Events list. Maximum of 100 events are allowed.
schedule string Schedule CRON syntax.
timeout integer Function maximum execution time in seconds.
Response
201 application/json
POST /functions
from appwrite.client import Client
from appwrite.services.functions import Functions
client = Client()
(client
.set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint
.set_project('5df5acd0d48c2') # Your project ID
.set_key('919c2d18fb5d4...a2ae413da83346ad2') # Your secret API key
)
functions = Functions(client)
result = functions.create('[FUNCTION_ID]', '[NAME]', ["role:all"], 'node-14.5')
Get Deployment
Get a code deployment by its unique ID.
Request
functionId string requiredFunction ID.
deploymentId string requiredDeployment ID.
Response
200 application/json
GET /functions/{functionId}/deployments/{deploymentId}
from appwrite.client import Client
from appwrite.services.functions import Functions
client = Client()
(client
.set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint
.set_project('5df5acd0d48c2') # Your project ID
.set_key('919c2d18fb5d4...a2ae413da83346ad2') # Your secret API key
)
functions = Functions(client)
result = functions.get_deployment('[FUNCTION_ID]', '[DEPLOYMENT_ID]')
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}
from appwrite.client import Client
from appwrite.services.functions import Functions
client = Client()
(client
.set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint
.set_project('5df5acd0d48c2') # Your project ID
.set_key('919c2d18fb5d4...a2ae413da83346ad2') # Your secret API key
)
functions = Functions(client)
result = functions.get_execution('[FUNCTION_ID]', '[EXECUTION_ID]')
Get Function
Get a function by its unique ID.
Request
functionId string requiredFunction ID.
Response
200 application/json
GET /functions/{functionId}
from appwrite.client import Client
from appwrite.services.functions import Functions
client = Client()
(client
.set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint
.set_project('5df5acd0d48c2') # Your project ID
.set_key('919c2d18fb5d4...a2ae413da83346ad2') # Your secret API key
)
functions = Functions(client)
result = functions.get('[FUNCTION_ID]')
List Deployments
Get a list of all the project's code deployments. You can use the query params to filter your results.
Request
functionId string requiredFunction ID.
search string Search term to filter your list results. Max length: 256 chars.
limit integer Maximum number of deployments to return in response. By default will return maximum 25 results. Maximum of 100 results allowed per request.
offset integer Offset value. The default value is 0. Use this value to manage pagination. learn more about pagination
cursor string ID of the deployment used as the starting point for the query, excluding the deployment itself. Should be used for efficient pagination when working with large sets of data. learn more about pagination
cursorDirection string Direction of the cursor, can be either 'before' or 'after'.
orderType string Order result by ASC or DESC order.
Response
200 application/json
GET /functions/{functionId}/deployments
from appwrite.client import Client
from appwrite.services.functions import Functions
client = Client()
(client
.set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint
.set_project('5df5acd0d48c2') # Your project ID
.set_key('919c2d18fb5d4...a2ae413da83346ad2') # Your secret API key
)
functions = Functions(client)
result = functions.list_deployments('[FUNCTION_ID]')
List Executions
Get a list of all the current user function execution logs. You can use the query params to filter your results. On admin mode, this endpoint will return a list of all of the project's executions. Learn more about different API modes.
Request
functionId string requiredFunction ID.
limit integer Maximum number of executions to return in response. By default will return maximum 25 results. Maximum of 100 results allowed per request.
offset integer Offset value. The default value is 0. Use this value to manage pagination. learn more about pagination
search string Search term to filter your list results. Max length: 256 chars.
cursor string ID of the execution used as the starting point for the query, excluding the execution itself. Should be used for efficient pagination when working with large sets of data. learn more about pagination
cursorDirection string Direction of the cursor, can be either 'before' or 'after'.
Response
200 application/json
GET /functions/{functionId}/executions
from appwrite.client import Client
from appwrite.services.functions import Functions
client = Client()
(client
.set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint
.set_project('5df5acd0d48c2') # Your project ID
.set_key('919c2d18fb5d4...a2ae413da83346ad2') # Your secret API key
)
functions = Functions(client)
result = functions.list_executions('[FUNCTION_ID]')
List Functions
Get a list of all the project's functions. You can use the query params to filter your results.
Request
search string Search term to filter your list results. Max length: 256 chars.
limit integer Maximum number of functions to return in response. By default will return maximum 25 results. Maximum of 100 results allowed per request.
offset integer Offset value. The default value is 0. Use this value to manage pagination. learn more about pagination
cursor string ID of the function used as the starting point for the query, excluding the function itself. Should be used for efficient pagination when working with large sets of data. learn more about pagination
cursorDirection string Direction of the cursor, can be either 'before' or 'after'.
orderType string Order result by ASC or DESC order.
Response
200 application/json
GET /functions
from appwrite.client import Client
from appwrite.services.functions import Functions
client = Client()
(client
.set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint
.set_project('5df5acd0d48c2') # Your project ID
.set_key('919c2d18fb5d4...a2ae413da83346ad2') # Your secret API key
)
functions = Functions(client)
result = functions.list()
List runtimes
Get a list of all runtimes that are currently active on your instance.
Response
200 application/json
GET /functions/runtimes
from appwrite.client import Client
from appwrite.services.functions import Functions
client = Client()
(client
.set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint
.set_project('5df5acd0d48c2') # Your project ID
.set_key('919c2d18fb5d4...a2ae413da83346ad2') # Your secret API key
)
functions = Functions(client)
result = functions.list_runtimes()
Update Function
Update function by its unique ID.
Request
functionId string requiredFunction ID.
name string requiredFunction name. Max length: 128 chars.
execute array requiredAn array of strings with execution permissions. By default no user is granted with any execute permissions. learn more about permissions and get a full list of available permissions. Maximum of 100 scopes are allowed, each 64 characters long.
vars object Key-value JSON object that will be passed to the function as environment variables.
events array Events list. Maximum of 100 events are allowed.
schedule string Schedule CRON syntax.
timeout integer Maximum execution time in seconds.
Response
200 application/json
PUT /functions/{functionId}
from appwrite.client import Client
from appwrite.services.functions import Functions
client = Client()
(client
.set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint
.set_project('5df5acd0d48c2') # Your project ID
.set_key('919c2d18fb5d4...a2ae413da83346ad2') # Your secret API key
)
functions = Functions(client)
result = functions.update('[FUNCTION_ID]', '[NAME]', ["role:all"])
Update Function Deployment
Update the function code deployment ID using the unique function ID. Use this endpoint to switch the code deployment that should be executed by the execution endpoint.
Request
functionId string requiredFunction ID.
deploymentId string requiredDeployment ID.
Response
200 application/json
PATCH /functions/{functionId}/deployments/{deploymentId}
from appwrite.client import Client
from appwrite.services.functions import Functions
client = Client()
(client
.set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint
.set_project('5df5acd0d48c2') # Your project ID
.set_key('919c2d18fb5d4...a2ae413da83346ad2') # Your secret API key
)
functions = Functions(client)
result = functions.update_deployment('[FUNCTION_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}
from appwrite.client import Client
from appwrite.services.functions import Functions
client = Client()
(client
.set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint
.set_project('5df5acd0d48c2') # Your project ID
.set_key('919c2d18fb5d4...a2ae413da83346ad2') # Your secret API key
)
functions = Functions(client)
result = functions.delete_deployment('[FUNCTION_ID]', '[DEPLOYMENT_ID]')
Delete Function
Delete a function by its unique ID.
Request
functionId string requiredFunction ID.
Response
204 application/json
DELETE /functions/{functionId}
from appwrite.client import Client
from appwrite.services.functions import Functions
client = Client()
(client
.set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint
.set_project('5df5acd0d48c2') # Your project ID
.set_key('919c2d18fb5d4...a2ae413da83346ad2') # Your secret API key
)
functions = Functions(client)
result = functions.delete('[FUNCTION_ID]')
Retry Build
Request
functionId string requiredFunction ID.
deploymentId string requiredDeployment ID.
buildId string requiredBuild unique ID.
Response
204 application/json
POST /functions/{functionId}/deployments/{deploymentId}/builds/{buildId}
from appwrite.client import Client
from appwrite.services.functions import Functions
client = Client()
(client
.set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint
.set_project('5df5acd0d48c2') # Your project ID
.set_key('919c2d18fb5d4...a2ae413da83346ad2') # Your secret API key
)
functions = Functions(client)
result = functions.retry_build('[FUNCTION_ID]', '[DEPLOYMENT_ID]', '[BUILD_ID]')