Functions

CLIENT

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.

Base URL
https://cloud.appwrite.io/v1

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
      required

      Function 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

    • search string

      Search term to filter your list results. Max length: 256 chars.

  • Response
Endpoint
GET /functions/{functionId}/executions
Web
import { Client, Functions } from "appwrite";

const client = new Client()
    .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint
    .setProject('<YOUR_PROJECT_ID>'); // Your project ID

const functions = new Functions(client);

const result = await functions.listExecutions(
    '<FUNCTION_ID>', // functionId
    [], // queries (optional)
    '<SEARCH>' // search (optional)
);

console.log(result);

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
      required

      Function 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
Endpoint
POST /functions/{functionId}/executions
Web
import { Client, Functions, ExecutionMethod } from "appwrite";

const client = new Client()
    .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint
    .setProject('<YOUR_PROJECT_ID>'); // Your project ID

const functions = new Functions(client);

const result = await functions.createExecution(
    '<FUNCTION_ID>', // functionId
    '<BODY>', // body (optional)
    false, // async (optional)
    '<PATH>', // path (optional)
    ExecutionMethod.GET, // method (optional)
    {}, // headers (optional)
    '' // scheduledAt (optional)
);

console.log(result);

Get execution

Get a function execution log by its unique ID.

  • Request
    • functionId string
      required

      Function ID.

    • executionId string
      required

      Execution ID.

  • Response
Endpoint
GET /functions/{functionId}/executions/{executionId}
Web
import { Client, Functions } from "appwrite";

const client = new Client()
    .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint
    .setProject('<YOUR_PROJECT_ID>'); // Your project ID

const functions = new Functions(client);

const result = await functions.getExecution(
    '<FUNCTION_ID>', // functionId
    '<EXECUTION_ID>' // executionId
);

console.log(result);