Method: Appwrite::Functions#create

Defined in:
lib/appwrite/services/functions.rb

#create(function_id:, name:, execute:, runtime:, vars: nil, events: nil, schedule: nil, timeout: nil) ⇒ Function

Create a new function. You can pass a list of [permissions](/docs/permissions) to allow different project users or team with access to execute the function using the client API.

Parameters:

  • function_id (string)

    Function 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)

    Function name. Max length: 128 chars.

  • execute (array)

    An array of strings with execution permissions. By default no user is granted with any execute permissions. [learn more about permissions](appwrite.io/docs/permissions) and get a full list of available permissions. Maximum of 100 scopes are allowed, each 64 characters long.

  • runtime (string)

    Execution runtime.

  • vars (object) (defaults to: nil)

    Key-value JSON object that will be passed to the function as environment variables.

  • events (array) (defaults to: nil)

    Events list. Maximum of 100 events are allowed.

  • schedule (string) (defaults to: nil)

    Schedule CRON syntax.

  • timeout (number) (defaults to: nil)

    Function maximum execution time in seconds.

Returns:

  • (Function)


56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/appwrite/services/functions.rb', line 56

def create(function_id:, name:, execute:, runtime:, vars: nil, events: nil, schedule: nil, timeout: nil)
    if function_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "functionId"')
    end

    if name.nil?
        raise Appwrite::Exception.new('Missing required parameter: "name"')
    end

    if execute.nil?
        raise Appwrite::Exception.new('Missing required parameter: "execute"')
    end

    if runtime.nil?
        raise Appwrite::Exception.new('Missing required parameter: "runtime"')
    end

    path = '/functions'

    params = {
        functionId: function_id,
        name: name,
        execute: execute,
        runtime: runtime,
        vars: vars,
        events: events,
        schedule: schedule,
        timeout: timeout,
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'POST',
        path: path,
        headers: headers,
        params: params,
        response_type: Models::Function
    )
end