Class: Appwrite::Functions

Inherits:
Service
  • Object
show all
Defined in:
lib/appwrite/services/functions.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Functions

Returns a new instance of Functions.



5
6
7
# File 'lib/appwrite/services/functions.rb', line 5

def initialize(client)
    @client = client
end

Instance Method Details

#create(function_id:, name:, runtime:, execute: nil, events: nil, schedule: nil, timeout: nil, enabled: nil, logging: nil, entrypoint: nil, commands: nil, scopes: nil, installation_id: nil, provider_repository_id: nil, provider_branch: nil, provider_silent_mode: nil, provider_root_directory: nil, provider_branches: nil, provider_paths: nil, build_specification: nil, runtime_specification: nil, deployment_retention: nil, interval: nil, description: nil) ⇒ 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.

Parameters:

  • function_id (String) —

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

    Function name. Max length: 128 chars.

  • runtime (Runtime) —

    Execution runtime.

  • execute (Array) (defaults to: nil) —

    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) (defaults to: nil) —

    Events list. Maximum of 100 events are allowed.

  • schedule (String) (defaults to: nil) —

    Schedule CRON syntax. Cannot be combined with interval.

  • timeout (Integer) (defaults to: nil) —

    Function maximum execution time in seconds.

  • [] —

    enabled 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 When disabled, executions will exclude logs and errors, and will be slightly faster.

  • entrypoint (String) (defaults to: nil) —

    Entrypoint File. This path is relative to the "providerRootDirectory".

  • commands (String) (defaults to: nil) —

    Build Commands.

  • scopes (Array) (defaults to: nil) —

    List of scopes allowed for API key auto-generated for every execution. Maximum of 200 scopes are allowed.

  • installation_id (String) (defaults to: nil) —

    Appwrite Installation ID for VCS (Version Control System) deployment.

  • provider_repository_id (String) (defaults to: nil) —

    Repository ID of the repo linked to the function.

  • provider_branch (String) (defaults to: nil) —

    Production branch for the repo linked to the function.

  • [] —

    provider_silent_mode 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.

  • provider_root_directory (String) (defaults to: nil) —

    Path to function code in the linked repo.

  • provider_branches (Array) (defaults to: nil) —

    List of branch name patterns to trigger automatic deployments. Supports wildcards. Leave empty to deploy on all branches.

  • provider_paths (Array) (defaults to: nil) —

    List of file path patterns to trigger automatic deployments. Supports wildcards. Leave empty to deploy on all file changes.

  • build_specification (String) (defaults to: nil) —

    Build specification for the function deployments.

  • runtime_specification (String) (defaults to: nil) —

    Runtime specification for the function executions.

  • deployment_retention (Integer) (defaults to: nil) —

    Days to keep non-active deployments before deletion. Value 0 keeps all deployments unless the server applies a default retention.

  • interval (Integer) (defaults to: nil) —

    Minutes between scheduled executions. Appwrite picks when within each interval the function runs. Use 0 to disable. Cannot be combined with schedule.

  • description (String) (defaults to: nil) —

    Optional description for the function.

Returns:

  • (Function)


75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/appwrite/services/functions.rb', line 75

def create(
    function_id:,
    name:,
    runtime:,
    execute: nil,
    events: nil,
    schedule: nil,
    timeout: nil,
    enabled: nil,
    logging: nil,
    entrypoint: nil,
    commands: nil,
    scopes: nil,
    installation_id: nil,
    provider_repository_id: nil,
    provider_branch: nil,
    provider_silent_mode: nil,
    provider_root_directory: nil,
    provider_branches: nil,
    provider_paths: nil,
    build_specification: nil,
    runtime_specification: nil,
    deployment_retention: nil,
    interval: nil,
    description: 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 runtime.nil?
        raise Appwrite::Exception.new('Missing required parameter: "runtime"')
    end

    api_path = '/functions'

    api_params = {
        functionId: function_id,
        name: name,
        runtime: runtime,
        execute: execute,
        events: events,
        schedule: schedule,
        timeout: timeout,
        enabled: enabled,
        logging: logging,
        entrypoint: entrypoint,
        commands: commands,
        scopes: scopes,
        installationId: installation_id,
        providerRepositoryId: provider_repository_id,
        providerBranch: provider_branch,
        providerSilentMode: provider_silent_mode,
        providerRootDirectory: provider_root_directory,
        providerBranches: provider_branches,
        providerPaths: provider_paths,
        buildSpecification: build_specification,
        runtimeSpecification: runtime_specification,
        deploymentRetention: deployment_retention,
        interval: interval,
        description: description,
    }

    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "content-type": 'application/json',
        "accept": 'application/json',
    }

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

#create_deployment(function_id:, code:, activate:, entrypoint: nil, commands: nil, on_progress: nil) ⇒ 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.

Parameters:

  • function_id (String) —

    Function ID.

  • code (file) —

    Gzip 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 Automatically activate the deployment when it is finished building.

  • entrypoint (String) (defaults to: nil) —

    Entrypoint File.

  • commands (String) (defaults to: nil) —

    Build Commands.

Returns:

  • (Deployment)


488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
# File 'lib/appwrite/services/functions.rb', line 488

def create_deployment(
    function_id:,
    code:,
    activate:,
    entrypoint: nil,
    commands: nil,
    on_progress: nil
)
    if function_id.nil? || function_id == ''
        raise Appwrite::Exception.new('Missing required parameter: "functionId"')
    end

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

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

    api_path = '/functions/{functionId}/deployments'
        .gsub('{functionId}', @client.encode_path(function_id))

    api_params = {
        entrypoint: entrypoint,
        commands: commands,
        code: code,
        activate: activate,
    }

    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "content-type": 'multipart/form-data',
        "accept": 'application/json',
    }

    id_param_name = nil
    param_name = 'code'

    @client.chunked_upload(
        path: api_path,
        headers: api_headers,
        params: api_params,
        param_name: param_name,
        id_param_name: id_param_name,
        on_progress: on_progress,
        method: 'POST',
        response_type: Models::Deployment
    )
end

#create_duplicate_deployment(function_id:, deployment_id:, build_id: nil) ⇒ 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.

Parameters:

  • function_id (String) —

    Function ID.

  • deployment_id (String) —

    Deployment ID.

  • build_id (String) (defaults to: nil) —

    Build unique ID.

Returns:

  • (Deployment)


550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
# File 'lib/appwrite/services/functions.rb', line 550

def create_duplicate_deployment(
    function_id:,
    deployment_id:,
    build_id: nil
)
    if function_id.nil? || function_id == ''
        raise Appwrite::Exception.new('Missing required parameter: "functionId"')
    end

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

    api_path = '/functions/{functionId}/deployments/duplicate'
        .gsub('{functionId}', @client.encode_path(function_id))

    api_params = {
        deploymentId: deployment_id,
        buildId: build_id,
    }

    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "content-type": 'application/json',
        "accept": 'application/json',
    }

    @client.call(
        method: 'POST',
        path: api_path,
        headers: api_headers,
        params: api_params,
        response_type: Models::Deployment
    )
end

#create_execution(function_id:, body: nil, async: nil, xpath: nil, method: nil, headers: nil, scheduled_at: nil) ⇒ 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.

Parameters:

  • function_id (String) —

    Function ID.

  • body (String) (defaults to: nil) —

    HTTP body of execution. Default value is empty string.

  • [] —

    async Execute code in the background. Default value is false.

  • xpath (String) (defaults to: nil) —

    HTTP path of execution. Path can include query params. Default value is /

  • method (ExecutionMethod) (defaults to: nil) —

    HTTP method of execution. Default value is POST.

  • headers (Hash) (defaults to: nil) —

    HTTP headers of execution. Defaults to empty.

  • scheduled_at (String) (defaults to: nil) —

    Scheduled execution time in ISO 8601 format. DateTime value must be in future with precision in minutes.

Returns:

  • (Execution)


931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
# File 'lib/appwrite/services/functions.rb', line 931

def create_execution(
    function_id:,
    body: nil,
    async: nil,
    xpath: nil,
    method: nil,
    headers: nil,
    scheduled_at: nil
)
    if function_id.nil? || function_id == ''
        raise Appwrite::Exception.new('Missing required parameter: "functionId"')
    end

    api_path = '/functions/{functionId}/executions'
        .gsub('{functionId}', @client.encode_path(function_id))

    api_params = {
        body: body,
        async: async,
        path: xpath,
        method: method,
        headers: headers,
        scheduledAt: scheduled_at,
    }

    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "content-type": 'application/json',
        "accept": 'application/json',
    }

    @client.call(
        method: 'POST',
        path: api_path,
        headers: api_headers,
        params: api_params,
        response_type: Models::Execution
    )
end

#create_template_deployment(function_id:, repository:, owner:, root_directory:, type:, reference:, activate: nil) ⇒ Deployment

Create a deployment based on a template.

Use this endpoint with combination of listTemplates to find the template details.

Parameters:

  • function_id (String) —

    Function ID.

  • repository (String) —

    Repository name of the template.

  • owner (String) —

    The name of the owner of the template.

  • root_directory (String) —

    Path to function code in the template repo.

  • type (TemplateReferenceType) —

    Type for the reference provided. Can be commit, branch, or tag

  • reference (String) —

    Reference value, can be a commit hash, branch name, or release tag

  • [] —

    activate Automatically activate the deployment when it is finished building.

Returns:

  • (Deployment)


601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
# File 'lib/appwrite/services/functions.rb', line 601

def create_template_deployment(
    function_id:,
    repository:,
    owner:,
    root_directory:,
    type:,
    reference:,
    activate: nil
)
    if function_id.nil? || function_id == ''
        raise Appwrite::Exception.new('Missing required parameter: "functionId"')
    end

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

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

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

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

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

    api_path = '/functions/{functionId}/deployments/template'
        .gsub('{functionId}', @client.encode_path(function_id))

    api_params = {
        repository: repository,
        owner: owner,
        rootDirectory: root_directory,
        type: type,
        reference: reference,
        activate: activate,
    }

    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "content-type": 'application/json',
        "accept": 'application/json',
    }

    @client.call(
        method: 'POST',
        path: api_path,
        headers: api_headers,
        params: api_params,
        response_type: Models::Deployment
    )
end

#create_variable(function_id:, variable_id:, key:, value:, secret: nil, description: nil) ⇒ Variable

Create a new function environment variable. These variables can be accessed in the function at runtime as environment variables.

Parameters:

  • function_id (String) —

    Function unique ID.

  • variable_id (String) —

    Variable 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.

  • key (String) —

    Variable key. Letters, digits and underscores only, must not start with a digit. Max length: 255 chars.

  • value (String) —

    Variable value. Max length: 8192 chars.

  • [] —

    secret Secret variables can be updated or deleted, but only functions can read them during build and runtime.

  • description (String) (defaults to: nil) —

    Optional description for the variable.

Returns:

  • (Variable)


1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
# File 'lib/appwrite/services/functions.rb', line 1096

def create_variable(
    function_id:,
    variable_id:,
    key:,
    value:,
    secret: nil,
    description: nil
)
    if function_id.nil? || function_id == ''
        raise Appwrite::Exception.new('Missing required parameter: "functionId"')
    end

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

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

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

    api_path = '/functions/{functionId}/variables'
        .gsub('{functionId}', @client.encode_path(function_id))

    api_params = {
        variableId: variable_id,
        key: key,
        value: value,
        secret: secret,
        description: description,
    }

    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "content-type": 'application/json',
        "accept": 'application/json',
    }

    @client.call(
        method: 'POST',
        path: api_path,
        headers: api_headers,
        params: api_params,
        response_type: Models::Variable
    )
end

#create_vcs_deployment(function_id:, type:, reference:, activate: nil) ⇒ Deployment

Create a deployment when a function is connected to VCS.

This endpoint lets you create deployment from a branch, commit, or a tag.

Parameters:

  • function_id (String) —

    Function ID.

  • type (VCSReferenceType) —

    Type of reference passed. Allowed values are: branch, commit

  • reference (String) —

    VCS reference to create deployment from. Depending on type this can be: branch name, commit hash

  • [] —

    activate Automatically activate the deployment when it is finished building.

Returns:

  • (Deployment)


671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
# File 'lib/appwrite/services/functions.rb', line 671

def create_vcs_deployment(
    function_id:,
    type:,
    reference:,
    activate: nil
)
    if function_id.nil? || function_id == ''
        raise Appwrite::Exception.new('Missing required parameter: "functionId"')
    end

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

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

    api_path = '/functions/{functionId}/deployments/vcs'
        .gsub('{functionId}', @client.encode_path(function_id))

    api_params = {
        type: type,
        reference: reference,
        activate: activate,
    }

    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "content-type": 'application/json',
        "accept": 'application/json',
    }

    @client.call(
        method: 'POST',
        path: api_path,
        headers: api_headers,
        params: api_params,
        response_type: Models::Deployment
    )
end

#delete(function_id:) ⇒ Object

Delete a function by its unique ID.

Parameters:

  • function_id (String) —

    Function ID.

Returns:

  • []



361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
# File 'lib/appwrite/services/functions.rb', line 361

def delete(
    function_id:
)
    if function_id.nil? || function_id == ''
        raise Appwrite::Exception.new('Missing required parameter: "functionId"')
    end

    api_path = '/functions/{functionId}'
        .gsub('{functionId}', @client.encode_path(function_id))

    api_params = {}

    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "content-type": 'application/json',
        "accept": 'application/json',
    }

    @client.call(
        method: 'DELETE',
        path: api_path,
        headers: api_headers,
        params: api_params,
    )
end

#delete_deployment(function_id:, deployment_id:) ⇒ Object

Delete a code deployment by its unique ID.

Parameters:

  • function_id (String) —

    Function ID.

  • deployment_id (String) —

    Deployment ID.

Returns:

  • []



757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
# File 'lib/appwrite/services/functions.rb', line 757

def delete_deployment(
    function_id:,
    deployment_id:
)
    if function_id.nil? || function_id == ''
        raise Appwrite::Exception.new('Missing required parameter: "functionId"')
    end

    if deployment_id.nil? || deployment_id == ''
        raise Appwrite::Exception.new('Missing required parameter: "deploymentId"')
    end

    api_path = '/functions/{functionId}/deployments/{deploymentId}'
        .gsub('{functionId}', @client.encode_path(function_id))
        .gsub('{deploymentId}', @client.encode_path(deployment_id))

    api_params = {}

    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "content-type": 'application/json',
        "accept": 'application/json',
    }

    @client.call(
        method: 'DELETE',
        path: api_path,
        headers: api_headers,
        params: api_params,
    )
end

#delete_execution(function_id:, execution_id:) ⇒ Object

Delete a function execution by its unique ID.

Parameters:

  • function_id (String) —

    Function ID.

  • execution_id (String) —

    Execution ID.

Returns:

  • []



1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
# File 'lib/appwrite/services/functions.rb', line 1015

def delete_execution(
    function_id:,
    execution_id:
)
    if function_id.nil? || function_id == ''
        raise Appwrite::Exception.new('Missing required parameter: "functionId"')
    end

    if execution_id.nil? || execution_id == ''
        raise Appwrite::Exception.new('Missing required parameter: "executionId"')
    end

    api_path = '/functions/{functionId}/executions/{executionId}'
        .gsub('{functionId}', @client.encode_path(function_id))
        .gsub('{executionId}', @client.encode_path(execution_id))

    api_params = {}

    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "content-type": 'application/json',
        "accept": 'application/json',
    }

    @client.call(
        method: 'DELETE',
        path: api_path,
        headers: api_headers,
        params: api_params,
    )
end

#delete_variable(function_id:, variable_id:) ⇒ Object

Delete a variable by its unique ID.

Parameters:

  • function_id (String) —

    Function unique ID.

  • variable_id (String) —

    Variable unique ID.

Returns:

  • []



1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
# File 'lib/appwrite/services/functions.rb', line 1242

def delete_variable(
    function_id:,
    variable_id:
)
    if function_id.nil? || function_id == ''
        raise Appwrite::Exception.new('Missing required parameter: "functionId"')
    end

    if variable_id.nil? || variable_id == ''
        raise Appwrite::Exception.new('Missing required parameter: "variableId"')
    end

    api_path = '/functions/{functionId}/variables/{variableId}'
        .gsub('{functionId}', @client.encode_path(function_id))
        .gsub('{variableId}', @client.encode_path(variable_id))

    api_params = {}

    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "content-type": 'application/json',
        "accept": 'application/json',
    }

    @client.call(
        method: 'DELETE',
        path: api_path,
        headers: api_headers,
        params: api_params,
    )
end

#get(function_id:) ⇒ Function

Get a function by its unique ID.

Parameters:

  • function_id (String) —

    Function ID.

Returns:

  • (Function)


221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
# File 'lib/appwrite/services/functions.rb', line 221

def get(
    function_id:
)
    if function_id.nil? || function_id == ''
        raise Appwrite::Exception.new('Missing required parameter: "functionId"')
    end

    api_path = '/functions/{functionId}'
        .gsub('{functionId}', @client.encode_path(function_id))

    api_params = {}

    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "accept": 'application/json',
    }

    @client.call(
        method: 'GET',
        path: api_path,
        headers: api_headers,
        params: api_params,
        response_type: Models::Function
    )
end

#get_deployment(function_id:, deployment_id:) ⇒ Deployment

Get a function deployment by its unique ID.

Parameters:

  • function_id (String) —

    Function ID.

  • deployment_id (String) —

    Deployment ID.

Returns:

  • (Deployment)


719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
# File 'lib/appwrite/services/functions.rb', line 719

def get_deployment(
    function_id:,
    deployment_id:
)
    if function_id.nil? || function_id == ''
        raise Appwrite::Exception.new('Missing required parameter: "functionId"')
    end

    if deployment_id.nil? || deployment_id == ''
        raise Appwrite::Exception.new('Missing required parameter: "deploymentId"')
    end

    api_path = '/functions/{functionId}/deployments/{deploymentId}'
        .gsub('{functionId}', @client.encode_path(function_id))
        .gsub('{deploymentId}', @client.encode_path(deployment_id))

    api_params = {}

    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "accept": 'application/json',
    }

    @client.call(
        method: 'GET',
        path: api_path,
        headers: api_headers,
        params: api_params,
        response_type: Models::Deployment
    )
end

#get_deployment_download(function_id:, deployment_id:, type: nil, token: nil) ⇒ Object

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.

Parameters:

  • function_id (String) —

    Function ID.

  • deployment_id (String) —

    Deployment ID.

  • type (DeploymentDownloadType) (defaults to: nil) —

    Deployment file to download. Can be: "source", "output".

  • token (String) (defaults to: nil) —

    Presigned source-download token for accessing this deployment without a session (jobs-service).

Returns:

  • []



799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
# File 'lib/appwrite/services/functions.rb', line 799

def get_deployment_download(
    function_id:,
    deployment_id:,
    type: nil,
    token: nil
)
    if function_id.nil? || function_id == ''
        raise Appwrite::Exception.new('Missing required parameter: "functionId"')
    end

    if deployment_id.nil? || deployment_id == ''
        raise Appwrite::Exception.new('Missing required parameter: "deploymentId"')
    end

    api_path = '/functions/{functionId}/deployments/{deploymentId}/download'
        .gsub('{functionId}', @client.encode_path(function_id))
        .gsub('{deploymentId}', @client.encode_path(deployment_id))

    api_params = {
        type: type,
        token: token,
    }

    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "accept": '*/*',
    }

    @client.call(
        method: 'GET',
        path: api_path,
        headers: api_headers,
        params: api_params,
    )
end

#get_execution(function_id:, execution_id:) ⇒ Execution

Get a function execution log by its unique ID.

Parameters:

  • function_id (String) —

    Function ID.

  • execution_id (String) —

    Execution ID.

Returns:

  • (Execution)


977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
# File 'lib/appwrite/services/functions.rb', line 977

def get_execution(
    function_id:,
    execution_id:
)
    if function_id.nil? || function_id == ''
        raise Appwrite::Exception.new('Missing required parameter: "functionId"')
    end

    if execution_id.nil? || execution_id == ''
        raise Appwrite::Exception.new('Missing required parameter: "executionId"')
    end

    api_path = '/functions/{functionId}/executions/{executionId}'
        .gsub('{functionId}', @client.encode_path(function_id))
        .gsub('{executionId}', @client.encode_path(execution_id))

    api_params = {}

    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "accept": 'application/json',
    }

    @client.call(
        method: 'GET',
        path: api_path,
        headers: api_headers,
        params: api_params,
        response_type: Models::Execution
    )
end

#get_variable(function_id:, variable_id:) ⇒ Variable

Get a variable by its unique ID.

Parameters:

  • function_id (String) —

    Function unique ID.

  • variable_id (String) —

    Variable unique ID.

Returns:

  • (Variable)


1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
# File 'lib/appwrite/services/functions.rb', line 1152

def get_variable(
    function_id:,
    variable_id:
)
    if function_id.nil? || function_id == ''
        raise Appwrite::Exception.new('Missing required parameter: "functionId"')
    end

    if variable_id.nil? || variable_id == ''
        raise Appwrite::Exception.new('Missing required parameter: "variableId"')
    end

    api_path = '/functions/{functionId}/variables/{variableId}'
        .gsub('{functionId}', @client.encode_path(function_id))
        .gsub('{variableId}', @client.encode_path(variable_id))

    api_params = {}

    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "accept": 'application/json',
    }

    @client.call(
        method: 'GET',
        path: api_path,
        headers: api_headers,
        params: api_params,
        response_type: Models::Variable
    )
end

#list(queries: nil, search: nil, total: nil) ⇒ FunctionList

Get a list of all the project's functions. You can use the query params to filter your results.

Parameters:

  • queries (Array) (defaults to: nil) —

    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) (defaults to: nil) —

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

  • [] —

    total When set to false, the total count returned will be 0 and will not be calculated.

Returns:

  • (FunctionList)


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/appwrite/services/functions.rb', line 17

def list(
    queries: nil,
    search: nil,
    total: nil
)
    api_path = '/functions'

    api_params = {
        queries: queries,
        search: search,
        total: total,
    }

    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "accept": 'application/json',
    }

    @client.call(
        method: 'GET',
        path: api_path,
        headers: api_headers,
        params: api_params,
        response_type: Models::FunctionList
    )
end

#list_deployments(function_id:, queries: nil, search: nil, total: nil) ⇒ DeploymentList

Get a list of all the function's code deployments. You can use the query params to filter your results.

Parameters:

  • function_id (String) —

    Function ID.

  • queries (Array) (defaults to: nil) —

    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) (defaults to: nil) —

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

  • [] —

    total When set to false, the total count returned will be 0 and will not be calculated.

Returns:

  • (DeploymentList)


437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
# File 'lib/appwrite/services/functions.rb', line 437

def list_deployments(
    function_id:,
    queries: nil,
    search: nil,
    total: nil
)
    if function_id.nil? || function_id == ''
        raise Appwrite::Exception.new('Missing required parameter: "functionId"')
    end

    api_path = '/functions/{functionId}/deployments'
        .gsub('{functionId}', @client.encode_path(function_id))

    api_params = {
        queries: queries,
        search: search,
        total: total,
    }

    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "accept": 'application/json',
    }

    @client.call(
        method: 'GET',
        path: api_path,
        headers: api_headers,
        params: api_params,
        response_type: Models::DeploymentList
    )
end

#list_executions(function_id:, queries: nil, total: nil) ⇒ ExecutionList

Get a list of all the current user function execution logs. You can use the query params to filter your results.

Parameters:

  • function_id (String) —

    Function ID.

  • queries (Array) (defaults to: nil) —

    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

  • [] —

    total When set to false, the total count returned will be 0 and will not be calculated.

Returns:

  • (ExecutionList)


886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
# File 'lib/appwrite/services/functions.rb', line 886

def list_executions(
    function_id:,
    queries: nil,
    total: nil
)
    if function_id.nil? || function_id == ''
        raise Appwrite::Exception.new('Missing required parameter: "functionId"')
    end

    api_path = '/functions/{functionId}/executions'
        .gsub('{functionId}', @client.encode_path(function_id))

    api_params = {
        queries: queries,
        total: total,
    }

    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "accept": 'application/json',
    }

    @client.call(
        method: 'GET',
        path: api_path,
        headers: api_headers,
        params: api_params,
        response_type: Models::ExecutionList
    )
end

#list_runtimes(total: nil) ⇒ RuntimeList

Get a list of all runtimes that are currently active on your instance.

Parameters:

  • [] —

    total When set to false, the total count returned will be 0 and will not be calculated.

Returns:

  • (RuntimeList)


162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/appwrite/services/functions.rb', line 162

def list_runtimes(
    total: nil
)
    api_path = '/functions/runtimes'

    api_params = {
        total: total,
    }

    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "accept": 'application/json',
    }

    @client.call(
        method: 'GET',
        path: api_path,
        headers: api_headers,
        params: api_params,
        response_type: Models::RuntimeList
    )
end

#list_specifications(type: nil, total: nil) ⇒ SpecificationList

List allowed function specifications for this instance.

Parameters:

  • type (String) (defaults to: nil) —

    Specification type to list. Can be one of: runtimes, builds. Defaults to runtimes.

  • [] —

    total When set to false, the total count returned will be 0 and will not be calculated.

Returns:

  • (SpecificationList)


191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/appwrite/services/functions.rb', line 191

def list_specifications(
    type: nil,
    total: nil
)
    api_path = '/functions/specifications'

    api_params = {
        type: type,
        total: total,
    }

    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "accept": 'application/json',
    }

    @client.call(
        method: 'GET',
        path: api_path,
        headers: api_headers,
        params: api_params,
        response_type: Models::SpecificationList
    )
end

#list_variables(function_id:, queries: nil, total: nil) ⇒ VariableList

Get a list of all variables of a specific function.

Parameters:

  • function_id (String) —

    Function unique ID.

  • queries (Array) (defaults to: nil) —

    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: key, resourceType, resourceId, secret

  • [] —

    total When set to false, the total count returned will be 0 and will not be calculated.

Returns:

  • (VariableList)


1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
# File 'lib/appwrite/services/functions.rb', line 1054

def list_variables(
    function_id:,
    queries: nil,
    total: nil
)
    if function_id.nil? || function_id == ''
        raise Appwrite::Exception.new('Missing required parameter: "functionId"')
    end

    api_path = '/functions/{functionId}/variables'
        .gsub('{functionId}', @client.encode_path(function_id))

    api_params = {
        queries: queries,
        total: total,
    }

    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "accept": 'application/json',
    }

    @client.call(
        method: 'GET',
        path: api_path,
        headers: api_headers,
        params: api_params,
        response_type: Models::VariableList
    )
end

#update(function_id:, name:, runtime: nil, execute: nil, events: nil, schedule: nil, timeout: nil, enabled: nil, logging: nil, entrypoint: nil, commands: nil, scopes: nil, installation_id: nil, provider_repository_id: nil, provider_branch: nil, provider_silent_mode: nil, provider_root_directory: nil, provider_branches: nil, provider_paths: nil, build_specification: nil, runtime_specification: nil, deployment_retention: nil, interval: nil, description: nil, email_enabled: nil) ⇒ Function

Update function by its unique ID.

Parameters:

  • function_id (String) —

    Function ID.

  • name (String) —

    Function name. Max length: 128 chars.

  • runtime (Runtime) (defaults to: nil) —

    Execution runtime.

  • execute (Array) (defaults to: nil) —

    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) (defaults to: nil) —

    Events list. Maximum of 100 events are allowed.

  • schedule (String) (defaults to: nil) —

    Schedule CRON syntax. Cannot be combined with interval.

  • timeout (Integer) (defaults to: nil) —

    Maximum execution time in seconds.

  • [] —

    enabled 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 When disabled, executions will exclude logs and errors, and will be slightly faster.

  • entrypoint (String) (defaults to: nil) —

    Entrypoint File. This path is relative to the "providerRootDirectory".

  • commands (String) (defaults to: nil) —

    Build Commands.

  • scopes (Array) (defaults to: nil) —

    List of scopes allowed for API Key auto-generated for every execution. Maximum of 200 scopes are allowed.

  • installation_id (String) (defaults to: nil) —

    Appwrite Installation ID for VCS (Version Controle System) deployment.

  • provider_repository_id (String) (defaults to: nil) —

    Repository ID of the repo linked to the function

  • provider_branch (String) (defaults to: nil) —

    Production branch for the repo linked to the function

  • [] —

    provider_silent_mode 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.

  • provider_root_directory (String) (defaults to: nil) —

    Path to function code in the linked repo.

  • provider_branches (Array) (defaults to: nil) —

    List of branch name patterns to trigger automatic deployments. Supports wildcards. Leave empty to deploy on all branches.

  • provider_paths (Array) (defaults to: nil) —

    List of file path patterns to trigger automatic deployments. Supports wildcards. Leave empty to deploy on all file changes.

  • build_specification (String) (defaults to: nil) —

    Build specification for the function deployments.

  • runtime_specification (String) (defaults to: nil) —

    Runtime specification for the function executions.

  • deployment_retention (Integer) (defaults to: nil) —

    Days to keep non-active deployments before deletion. Value 0 keeps all deployments unless the server applies a default retention.

  • interval (Integer) (defaults to: nil) —

    Minutes between scheduled executions. Appwrite picks when within each interval the function runs. Use 0 to disable. Cannot be combined with schedule. When omitted, the current interval is kept unless schedule is set.

  • description (String) (defaults to: nil) —

    Optional description for the function.

  • [] —

    email_enabled Enable inbound email triggering for this function. When false or omitted on create, SMTP recipients are rejected. Opt-in; default is off.

Returns:

  • (Function)


276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
# File 'lib/appwrite/services/functions.rb', line 276

def update(
    function_id:,
    name:,
    runtime: nil,
    execute: nil,
    events: nil,
    schedule: nil,
    timeout: nil,
    enabled: nil,
    logging: nil,
    entrypoint: nil,
    commands: nil,
    scopes: nil,
    installation_id: nil,
    provider_repository_id: nil,
    provider_branch: nil,
    provider_silent_mode: nil,
    provider_root_directory: nil,
    provider_branches: nil,
    provider_paths: nil,
    build_specification: nil,
    runtime_specification: nil,
    deployment_retention: nil,
    interval: nil,
    description: nil,
    email_enabled: nil
)
    if function_id.nil? || function_id == ''
        raise Appwrite::Exception.new('Missing required parameter: "functionId"')
    end

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

    api_path = '/functions/{functionId}'
        .gsub('{functionId}', @client.encode_path(function_id))

    api_params = {
        name: name,
        runtime: runtime,
        execute: execute,
        events: events,
        schedule: schedule,
        timeout: timeout,
        enabled: enabled,
        logging: logging,
        entrypoint: entrypoint,
        commands: commands,
        scopes: scopes,
        installationId: installation_id,
        providerRepositoryId: provider_repository_id,
        providerBranch: provider_branch,
        providerSilentMode: provider_silent_mode,
        providerRootDirectory: provider_root_directory,
        providerBranches: provider_branches,
        providerPaths: provider_paths,
        buildSpecification: build_specification,
        runtimeSpecification: runtime_specification,
        deploymentRetention: deployment_retention,
        interval: interval,
        description: description,
        emailEnabled: email_enabled,
    }

    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "content-type": 'application/json',
        "accept": 'application/json',
    }

    @client.call(
        method: 'PUT',
        path: api_path,
        headers: api_headers,
        params: api_params,
        response_type: Models::Function
    )
end

#update_deployment_status(function_id:, deployment_id:) ⇒ Deployment

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.

Parameters:

  • function_id (String) —

    Function ID.

  • deployment_id (String) —

    Deployment ID.

Returns:

  • (Deployment)


845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
# File 'lib/appwrite/services/functions.rb', line 845

def update_deployment_status(
    function_id:,
    deployment_id:
)
    if function_id.nil? || function_id == ''
        raise Appwrite::Exception.new('Missing required parameter: "functionId"')
    end

    if deployment_id.nil? || deployment_id == ''
        raise Appwrite::Exception.new('Missing required parameter: "deploymentId"')
    end

    api_path = '/functions/{functionId}/deployments/{deploymentId}/status'
        .gsub('{functionId}', @client.encode_path(function_id))
        .gsub('{deploymentId}', @client.encode_path(deployment_id))

    api_params = {}

    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "content-type": 'application/json',
        "accept": 'application/json',
    }

    @client.call(
        method: 'PATCH',
        path: api_path,
        headers: api_headers,
        params: api_params,
        response_type: Models::Deployment
    )
end

#update_function_deployment(function_id:, deployment_id:) ⇒ Function

Update the function active deployment. Use this endpoint to switch the code deployment that should be used when visitor opens your function.

Parameters:

  • function_id (String) —

    Function ID.

  • deployment_id (String) —

    Deployment ID.

Returns:

  • (Function)


394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
# File 'lib/appwrite/services/functions.rb', line 394

def update_function_deployment(
    function_id:,
    deployment_id:
)
    if function_id.nil? || function_id == ''
        raise Appwrite::Exception.new('Missing required parameter: "functionId"')
    end

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

    api_path = '/functions/{functionId}/deployment'
        .gsub('{functionId}', @client.encode_path(function_id))

    api_params = {
        deploymentId: deployment_id,
    }

    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "content-type": 'application/json',
        "accept": 'application/json',
    }

    @client.call(
        method: 'PATCH',
        path: api_path,
        headers: api_headers,
        params: api_params,
        response_type: Models::Function
    )
end

#update_variable(function_id:, variable_id:, key: nil, value: nil, secret: nil, description: nil) ⇒ Variable

Update variable by its unique ID.

Parameters:

  • function_id (String) —

    Function unique ID.

  • variable_id (String) —

    Variable unique ID.

  • key (String) (defaults to: nil) —

    Variable key. Letters, digits and underscores only, must not start with a digit. Max length: 255 chars.

  • value (String) (defaults to: nil) —

    Variable value. Max length: 8192 chars.

  • [] —

    secret Secret variables can be updated or deleted, but only functions can read them during build and runtime.

  • description (String) (defaults to: nil) —

    Optional description for the variable.

Returns:

  • (Variable)


1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
# File 'lib/appwrite/services/functions.rb', line 1194

def update_variable(
    function_id:,
    variable_id:,
    key: nil,
    value: nil,
    secret: nil,
    description: nil
)
    if function_id.nil? || function_id == ''
        raise Appwrite::Exception.new('Missing required parameter: "functionId"')
    end

    if variable_id.nil? || variable_id == ''
        raise Appwrite::Exception.new('Missing required parameter: "variableId"')
    end

    api_path = '/functions/{functionId}/variables/{variableId}'
        .gsub('{functionId}', @client.encode_path(function_id))
        .gsub('{variableId}', @client.encode_path(variable_id))

    api_params = {
        key: key,
        value: value,
        secret: secret,
        description: description,
    }

    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "content-type": 'application/json',
        "accept": 'application/json',
    }

    @client.call(
        method: 'PUT',
        path: api_path,
        headers: api_headers,
        params: api_params,
        response_type: Models::Variable
    )
end