Functions API
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.
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.
Rate Limits
This endpoint is limited to 60 requests in every 1 minutes per IP address. We use rate limits to avoid service abuse by users and as a security practice. Learn more about rate limiting.
HTTP Request
Name | Type | Description | |
functionId | required | string | Function ID. |
data | optional | string | String of custom data to send to function. |
async | optional | boolean | Execute code asynchronously. Default value is true. |
HTTP Response
Status Code | Content Type | Payload |
201 Created | application/json | Execution Object |
-
import { Client, Functions } from "appwrite"; const client = new Client(); const functions = new Functions(client); client .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; const promise = functions.createExecution('[FUNCTION_ID]'); promise.then(function (response) { console.log(response); // Success }, function (error) { console.log(error); // Failure });
-
import 'package:appwrite/appwrite.dart'; void main() { // Init SDK Client client = Client(); Functions functions = Functions(client); client .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = functions.createExecution( functionId: '[FUNCTION_ID]', ); result .then((response) { print(response); }).catchError((error) { print(error.response); }); }
-
import Appwrite func main() async throws { let client = Client() .setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint .setProject("5df5acd0d48c2") // Your project ID let functions = Functions(client) let execution = try await functions.createExecution( functionId: "[FUNCTION_ID]" ) print(String(describing: execution) }
-
import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch import io.appwrite.Client import io.appwrite.services.Functions class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) val client = Client(applicationContext) .setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint .setProject("5df5acd0d48c2") // Your project ID val functions = Functions(client) GlobalScope.launch { val response = functions.createExecution( functionId = "[FUNCTION_ID]", ) val json = response.body?.string() } } }
-
import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch import io.appwrite.Client import io.appwrite.services.Functions public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Client client = new Client(getApplicationContext()) .setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint .setProject("5df5acd0d48c2"); // Your project ID Functions functions = new Functions(client); functions.createExecution( "[FUNCTION_ID]", new Continuation<Object>() { @NotNull @Override public CoroutineContext getContext() { return EmptyCoroutineContext.INSTANCE; } @Override public void resumeWith(@NotNull Object o) { String json = ""; try { if (o instanceof Result.Failure) { Result.Failure failure = (Result.Failure) o; throw failure.exception; } else { Response response = (Response) o; json = response.body().string(); } } catch (Throwable th) { Log.e("ERROR", th.toString()); } } } ); } }
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.
HTTP Request
Name | Type | Description | |
functionId | required | string | Function ID. |
limit | optional | integer | Maximum number of executions to return in response. By default will return maximum 25 results. Maximum of 100 results allowed per request. |
offset | optional | integer | Offset value. The default value is 0. Use this value to manage pagination. learn more about pagination |
search | optional | string | Search term to filter your list results. Max length: 256 chars. |
cursor | optional | 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 | optional | string | Direction of the cursor, can be either 'before' or 'after'. |
HTTP Response
Status Code | Content Type | Payload |
200 OK | application/json | Executions List Object |
-
import { Client, Functions } from "appwrite"; const client = new Client(); const functions = new Functions(client); client .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; const promise = functions.listExecutions('[FUNCTION_ID]'); promise.then(function (response) { console.log(response); // Success }, function (error) { console.log(error); // Failure });
-
import 'package:appwrite/appwrite.dart'; void main() { // Init SDK Client client = Client(); Functions functions = Functions(client); client .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = functions.listExecutions( functionId: '[FUNCTION_ID]', ); result .then((response) { print(response); }).catchError((error) { print(error.response); }); }
-
import Appwrite func main() async throws { let client = Client() .setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint .setProject("5df5acd0d48c2") // Your project ID let functions = Functions(client) let executionList = try await functions.listExecutions( functionId: "[FUNCTION_ID]" ) print(String(describing: executionList) }
-
import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch import io.appwrite.Client import io.appwrite.services.Functions class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) val client = Client(applicationContext) .setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint .setProject("5df5acd0d48c2") // Your project ID val functions = Functions(client) GlobalScope.launch { val response = functions.listExecutions( functionId = "[FUNCTION_ID]", ) val json = response.body?.string() } } }
-
import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch import io.appwrite.Client import io.appwrite.services.Functions public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Client client = new Client(getApplicationContext()) .setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint .setProject("5df5acd0d48c2"); // Your project ID Functions functions = new Functions(client); functions.listExecutions( "[FUNCTION_ID]", new Continuation<Object>() { @NotNull @Override public CoroutineContext getContext() { return EmptyCoroutineContext.INSTANCE; } @Override public void resumeWith(@NotNull Object o) { String json = ""; try { if (o instanceof Result.Failure) { Result.Failure failure = (Result.Failure) o; throw failure.exception; } else { Response response = (Response) o; json = response.body().string(); } } catch (Throwable th) { Log.e("ERROR", th.toString()); } } } ); } }
Get Execution
Get a function execution log by its unique ID.
HTTP Request
Name | Type | Description | |
functionId | required | string | Function ID. |
executionId | required | string | Execution ID. |
HTTP Response
Status Code | Content Type | Payload |
200 OK | application/json | Execution Object |
-
import { Client, Functions } from "appwrite"; const client = new Client(); const functions = new Functions(client); client .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; const promise = functions.getExecution('[FUNCTION_ID]', '[EXECUTION_ID]'); promise.then(function (response) { console.log(response); // Success }, function (error) { console.log(error); // Failure });
-
import 'package:appwrite/appwrite.dart'; void main() { // Init SDK Client client = Client(); Functions functions = Functions(client); client .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = functions.getExecution( functionId: '[FUNCTION_ID]', executionId: '[EXECUTION_ID]', ); result .then((response) { print(response); }).catchError((error) { print(error.response); }); }
-
import Appwrite func main() async throws { let client = Client() .setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint .setProject("5df5acd0d48c2") // Your project ID let functions = Functions(client) let execution = try await functions.getExecution( functionId: "[FUNCTION_ID]", executionId: "[EXECUTION_ID]" ) print(String(describing: execution) }
-
import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch import io.appwrite.Client import io.appwrite.services.Functions class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) val client = Client(applicationContext) .setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint .setProject("5df5acd0d48c2") // Your project ID val functions = Functions(client) GlobalScope.launch { val response = functions.getExecution( functionId = "[FUNCTION_ID]", executionId = "[EXECUTION_ID]" ) val json = response.body?.string() } } }
-
import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch import io.appwrite.Client import io.appwrite.services.Functions public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Client client = new Client(getApplicationContext()) .setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint .setProject("5df5acd0d48c2"); // Your project ID Functions functions = new Functions(client); functions.getExecution( "[FUNCTION_ID]", "[EXECUTION_ID]" new Continuation<Object>() { @NotNull @Override public CoroutineContext getContext() { return EmptyCoroutineContext.INSTANCE; } @Override public void resumeWith(@NotNull Object o) { String json = ""; try { if (o instanceof Result.Failure) { Result.Failure failure = (Result.Failure) o; throw failure.exception; } else { Response response = (Response) o; json = response.body().string(); } } catch (Throwable th) { Log.e("ERROR", th.toString()); } } } ); } }
Retry Build
HTTP Request
Name | Type | Description | |
functionId | required | string | Function ID. |
deploymentId | required | string | Deployment ID. |
buildId | required | string | Build unique ID. |
HTTP Response
Status Code | Content Type | Payload |
204 No Content | - | - |
-
import { Client, Functions } from "appwrite"; const client = new Client(); const functions = new Functions(client); client .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; const promise = functions.retryBuild('[FUNCTION_ID]', '[DEPLOYMENT_ID]', '[BUILD_ID]'); promise.then(function (response) { console.log(response); // Success }, function (error) { console.log(error); // Failure });
-
import 'package:appwrite/appwrite.dart'; void main() { // Init SDK Client client = Client(); Functions functions = Functions(client); client .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = functions.retryBuild( functionId: '[FUNCTION_ID]', deploymentId: '[DEPLOYMENT_ID]', buildId: '[BUILD_ID]', ); result .then((response) { print(response); }).catchError((error) { print(error.response); }); }
-
import Appwrite func main() async throws { let client = Client() .setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint .setProject("5df5acd0d48c2") // Your project ID let functions = Functions(client) let result = try await functions.retryBuild( functionId: "[FUNCTION_ID]", deploymentId: "[DEPLOYMENT_ID]", buildId: "[BUILD_ID]" ) print(String(describing: result) }
-
import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch import io.appwrite.Client import io.appwrite.services.Functions class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) val client = Client(applicationContext) .setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint .setProject("5df5acd0d48c2") // Your project ID val functions = Functions(client) GlobalScope.launch { val response = functions.retryBuild( functionId = "[FUNCTION_ID]", deploymentId = "[DEPLOYMENT_ID]", buildId = "[BUILD_ID]" ) val json = response.body?.string() } } }
-
import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch import io.appwrite.Client import io.appwrite.services.Functions public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Client client = new Client(getApplicationContext()) .setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint .setProject("5df5acd0d48c2"); // Your project ID Functions functions = new Functions(client); functions.retryBuild( "[FUNCTION_ID]", "[DEPLOYMENT_ID]", "[BUILD_ID]" new Continuation<Object>() { @NotNull @Override public CoroutineContext getContext() { return EmptyCoroutineContext.INSTANCE; } @Override public void resumeWith(@NotNull Object o) { String json = ""; try { if (o instanceof Result.Failure) { Result.Failure failure = (Result.Failure) o; throw failure.exception; } else { Response response = (Response) o; json = response.body().string(); } } catch (Throwable th) { Log.e("ERROR", th.toString()); } } } ); } }