Eventing REST API

    +
    The Eventing REST API, available by default at port 8096, provides the methods available to work with and manipulate Couchbase Eventing Functions.
    Changes to the Eventing Function definition files made outside of this REST API or the interactive UI are only supported for version 7.0 (and above) if the Eventing schemas located in https://github.com/couchbase/eventing/tree/master/parser are adhered to.
    Table 1. Eventing Functions API (basic activation/deactivation)
    HTTP Method URI Path Description

    POST

    /api/v1/functions/[sample_name]/deploy

    Deploys an undeployed Function. Starting with version 6.5.0, this is the preferred invocation. A deploy CURL example is provided for reference.

    Sample API:

    curl -XPOST http://Administrator:password@192.168.1.5:8096/api/v1/functions/[sample_name]/deploy

    POST

    /api/v1/functions/[sample_name]/undeploy

    Undeploys a Function. Starting with version 6.5.0, this is the preferred invocation. An undeploy CURL example is provided for reference.

    Sample API:

    curl -XPOST http://Administrator:password@192.168.1.5:8096/api/v1/functions/[sample_name]/undeploy

    POST

    /api/v1/functions/[sample_name]/pause

    Pauses a Function and creates a DCP checkpoint such that on a subsequent resume no mutations will be lost. Starting with version 6.5.0, this is the preferred invocation. A pause CURL example is provided for reference.

    Sample API:

    curl -XPOST http://Administrator:password@192.168.1.5:8096/api/v1/functions/[sample_name]/pause

    POST

    /api/v1/functions/[sample_name]/resume

    Resumes a paused function from its paused DCP checkpoint. Starting with version 6.5.0, this is the preferred invocation. A resume CURL example is provided for reference.

    Sample API:

    curl -XPOST http://Administrator:password@192.168.1.5:8096/api/v1/functions/[sample_name]/resume
    Table 2. Eventing Functions API (advanced)
    HTTP Method URI Path Description

    POST

    /api/v1/functions/[function_name]

    Import or create a single Function. The Function name in the body must match that on the URL. Function definition includes current settings. The POST data or POST data file must be a single JSON object or an array containing a single JSON object

    Sample API (from file):

    curl -XPOST  -d @./[sample_name].json http://Administrator:password@192.168.1.5:8096/api/v1/functions/[sample_name]

    POST

    /api/v1/functions/

    Imports or creates multiple Functions. Function names must be unique. When multiple Functions have the same name, an error is reported. The POST data or POST data file must be either a single JSON object or an array containing a one or more JSON objects

    Sample API (from file):

    curl -XPOST  -d @./[array_of_functions].json http://Administrator:password@192.168.1.5:8096/api/v1/functions

    POST

    /api/v1/import/

    Imports multiple Functions. Function names must be unique. When multiple Functions have the same name, an error is reported. The POST data or POST data file must be either a single JSON object or an array containing a one or more JSON objects Note if any Function’s language_compatibility field is missing the value will be set to 6.0.0 (unlike the /api/v1/functions above which will set the value to the highest version supported by the server).

    Sample API (from file):

    curl -XPOST  -d @./[array_of_functions].json http://Administrator:password@192.168.1.5:8096/api/v1/import

    GET

    /api/v1/functions/[sample_name]

    View a definition of a Function. Provides a listing of a complete Function definition available in the cluster. The Function could be in any state: deployed, undeployed, or paused. If saved to a file the function definition can be imported into the cluster or a different cluster. However any changes to the function definition made to the file outside the UI are discouraged.

    Sample API (to standard out):

    curl -XGET http://Administrator:password@192.168.1.5:8096/api/v1/functions/[sample_name]

    Sample API (to file):

    curl -XGET http://Administrator:password@192.168.1.5:8096/api/v1/functions/[sample_name] -o [sample_name].json

    GET

    /api/v1/functions

    View definitions of all Functions. Provides an array of definitions of all Functions available in the cluster. The Functions could be in any state: deployed, undeployed, or paused. If saved to a file the function definitions can be imported into the cluster or a different cluster. However any changes to the function definition made to the file outside the UI are discouraged.

    Sample API (to standard out):

    curl -XGET http://Administrator:password@192.168.1.5:8096/api/v1/functions

    Sample API (to file):

    curl -XGET http://Administrator:password@192.168.1.5:8096/api/v1/functions -o array_of_functions.json

    GET

    /api/v1/export

    This is a convenience method to export all function definitions. Exported functions are always set to undeployed state at the time of export, regardless of the state in the cluster at time of export. If saved to a file the function definitions can be imputed into the cluster or a different cluster. However any changes to the function definition made to the file outside the UI are discouraged.

    Sample API (to standard out):

    curl -XGET http://Administrator:password@192.168.1.5:8096/api/v1/export

    Sample API (to file):

    curl -XGET http://Administrator:password@192.168.1.5:8096/api/v1/export -o array_of_functions.json

    DELETE

    /api/v1/functions/[function_name]

    Deletes a specific Function from the cluster. WARNING: Use this API with caution as it is irreversible.

    Sample API:

    curl -XDELETE http://Administrator:password@192.168.1.5:8096/api/v1/functions/[sample_name]

    DELETE

    /api/v1/functions

    Deletes multiple Functions (as in all Functions) from the cluster. WARNING: Use this API with caution as it is irreversible.

    Sample API:

    curl -XDELETE http://Administrator:password@192.168.1.5:8096/api/v1/functions

    GET

    /api/v1/functions/[function_name]/settings

    Export or return the full definition for one Eventing Function in the cluster. The definition can be subsequently imported. However any changes to the function definition made to the file outside the UI are discouraged.

    Sample API (to standard out):

    curl http://Administrator:password@192.168.1.5:8096/api/v1/functions/[sample_name]/settings

    Sample API (to file):

    curl -XGET http://Administrator:password@192.168.1.5:8096/api/v1/functions/[sample_name]/settings -o [sample_name].json

    POST

    /api/v1/functions/[function_name]/settings

    Updates an undeployed or paused function with the provided setting. Note settings can only be altered when the function is paused or undeployed, attempting to adjust a deployed function will result in an error. During an edit, settings provided are merged. Unspecified attributes retain their prior values. Note that you must always specify deployment_status (deployed/undeployed) and processing_status (paused/not-paused) when using this REST endpoint to update any option or set of options.

    The current values of deployment_status and processing_status can be queried via api/v1/status or api/v1/status/[sample_name]

    By adjusting deployment_status and processing_status this command can also deploy or resume a function, however it cannot pause or undeploy a function.

    Sample API (alter worker_count):

    curl -XPOST -d '{"deployment_status":false,"processing_status":false,"worker_count":6}' http://Administrator:password@192.168.1.5:8096/api/v1/functions/[sample_name]/settings

    Sample API (alter app_log_max_files and app_log_max_size) this function is currently undeployed:

    curl -XPOST -d '{"deployment_status":false,"processing_status":false,"app_log_max_files":5,"app_log_max_size":10485760}' http://Administrator:password@192.168.1.5:8096/api/v1/functions/[sample_name]/settings

    Sample API (alter timer_context_size) this function is currently paused:

    curl -XPOST -d '{"deployment_status":true,"processing_status":false,"timer_context_size":2048}' http://Administrator:password@192.168.1.5:8096/api/v1/functions/[sample_name]/settings

    Sample API (alter worker_count AND resume) this function is currently paused:

    curl -XPOST -d '{"deployment_status":true,"processing_status":true,"worker_count":8}' http://Administrator:password@192.168.1.5:8096/api/v1/functions/[sample_name]/settings

    GET

    /api/v1/functions/[function_name]/config

    Export or return the configuration of the source keyspace and the eventing storage (metadata) keyspace for one Eventing Function in the cluster. The definition can be subsequently imported. However any changes to the function definition made to the file outside the UI are discouraged.

    Sample API (to standard out):

    curl http://Administrator:password@192.168.1.5:8096/api/v1/functions/[sample_name]/config

    Sample API (to file):

    curl -XGET http://Administrator:password@192.168.1.5:8096/api/v1/functions/[sample_name]/config -o [sample_name].json

    POST

    /api/v1/functions/[function_name]/config

    Import the configuration and alter the source keyspace and the eventing storage (metadata) keyspace for one Eventing Function in the cluster. You can only change these values if a function is in the undeployed state and the two keyspaces exist.

    Sample API (alter source and eventing storage keyspaces):

    curl -XPOST http://Administrator:password@192.168.1.5:8096/api/v1/functions/[sample_name]/config -d '{ "source_bucket": "bulk", "cust01": "orders", "source_collection": "customer01", "metadata_bucket": "rr100", "metadata_scope": "eventing", "metadata_collection": "metadata" }'

    Sample API (alter source and eventing storage keyspaces from a file):

    curl -XPOST http://Administrator:password@192.168.1.5:8096/api/v1/functions/[sample_name]/config -d @./[sample_name].json

    GET

    /api/v1/functions/[function_name]/appcode

    Export only the JavaScript code for one Eventing Function in the cluster. Note the JavaScript is not escaped (unlike /api/v1/functions/[function_name]) and the code is runnable in other environments. The JavaScript code can be subsequently imported. However any changes to the function definition made to the file outside the UI are discouraged.

    Sample API (to standard out):

    curl -XGET http://Administrator:password@192.168.1.5:8096/api/v1/functions/[sample_name]/appcode

    Sample API (to file):

    curl -XGET http://Administrator:password@192.168.1.5:8096/api/v1/functions/[sample_name]/appcode -o [sample_name].json

    POST

    /api/v1/functions/[function_name]/appcode

    Import only the JavaScript code for one Eventing Function in the cluster. Note the JavaScript supplied is not escaped (unlike /api/v1/functions/[function_name]) and could come from other environments. It is highly recommended that you use the flag --data-binary or --upload-file when importing your JavaScript "appcode" fragments to avoid potential encoding issues due to string escaping.

    Sample API (import and replace JavaScript):

    curl -XPOST http://Administrator:password@192.168.1.5:8096/api/v1/functions/aa/appcode --data-binary 'function OnUpdate(doc, meta) { log("id",meta.id); }'

    Sample API (import and replace JavaScript from a file, do not use -d):

    curl -XPOST http://Administrator:password@192.168.1.5:8096/api/v1/functions/[sample_name]/import --data-binary @./[sample_name].json

    or

    curl -XGET http://Administrator:password@192.168.1.5:8096/api/v1/functions/[sample_name]/import --upload-file ./[sample_name].json
    Table 3. Eventing Status API (advanced)
    HTTP Method URI Path Description

    GET

    /api/v1/status

    Returns a list (array) of all Eventing Functions showing their corresponding composite_status. A Function’s status can have one of the following values - undeployed, deploying, deployed, undeploying, paused, and 'pausing. Note, there is no value of resuming when resuming a paused Eventing Function the composite_status will return deploying until it reaches the deployed state.

    Sample API (status):

    curl -XGET http://Administrator:password@192.168.1.5:8096/api/v1/status

    GET

    /api/v1/status/[sample_name]

    Returns a specific Eventing Functions showing its corresponding composite_status. It can have one of the following values - undeployed, deploying, deployed, undeploying, paused, and 'pausing. Note, there is no value of resuming when resuming a paused Eventing Function the composite_status will return deploying until it reaches the deployed state.

    Sample API (status):

    curl -XGET http://Administrator:password@192.168.1.5:8096/api/v1/status/[sample_name]
    Table 4. Eventing List API (advanced)
    HTTP Method URI Path Description

    GET

    /api/v1/list/functions

    Returns a list (array) of the names of all Eventing Functions in the cluster. The returned list can also be filtered by the following: deployed status true or false (in this case paused is considered deployed), source_bucket filter by the bucket with the listen to keyspace, and function_type notsbm or sbm (the later if the functions that modifies its own listen to keyspace).

    Sample API (list):

    curl -XGET http://Administrator:password@192.168.1.5:8096/api/v1/list/functions

    GET

    /api/v1/list/functions/query?deployed=true

    Returns a list (array) of the names of all deployed (or paused) Eventing Functions in the cluster. Note, if we had specified deployed=false we would get all undeployed functions.

    Sample API (status):

    curl -XGET http://Administrator:password@192.168.1.5:8096/api/v1/list/functions/query?deployed=true

    GET

    /api/v1/list/functions/query?source_bucket=[bucket_name]

    Returns a list (array) of the names of Eventing Functions in the cluster that have a source keyspace under a particular bucket.

    Sample API (status):

    curl -XGET http://Administrator:password@192.168.1.5:8096/api/v1/list/functions/query?source_bucket=[bucket_name]

    GET

    /api/v1/list/functions/query?function_type=sbm

    Returns a list (array) of the names of Eventing Functions in the cluster that modify their own a source keyspace.

    Sample API (status):

    curl -XGET http://Administrator:password@192.168.1.5:8096/api/v1/list/functions/query?function_type=sbm
    Table 5. Eventing Global Config API (advanced)
    HTTP Method URI Path Description

    GET

    /api/v1/config

    List global configuration. The response shows all global Eventing settings. There are currently just two settings: enable_debugger (default value of false) and ram_quota (default value of 256 MB). Both of these settings can also be adjusted via the UI.

    Sample API:

    curl -XGET http://Administrator:password@192.168.1.5:8096/api/v1/config

    POST

    /api/v1/config

    Modify global configuration. During an edit, settings provided are merged. Unspecified attributes retain their prior values. The response indicates whether the Eventing service must be restarted for the new changes to take effect.

    Sample API (alter ram_quota):

    curl -XPOST -d '{"ram_quota": 512}' http://Administrator:password@192.168.1.5:8096/api/v1/config

    Sample API (alter enable_debugger):

    curl -XPOST -d '{"enable_debugger": true}' http://Administrator:password@192.168.1.5:8096/api/v1/config
    Table 6. Eventing Statistics API
    HTTP Method URI Path Description

    GET

    /api/v1/stats?type=full

    Retrieve all statistics for the node. This will return the full statistics set inclusive of events processing, events remaining, execution, failure, latency, worker PIDs and sequence processed.

    Omitting the parameter type=full will exclude dcp_event_backlog_per_vb, doc_timer_debug_stats, latency_stats, plasma_stats, and seqs_processed from the response.

    Sample API (basic):

    curl -XGET http://Administrator:password@192.168.1.5:8096/api/v1/stats

    Sample API (full):

    curl -XGET http://Administrator:password@192.168.1.5:8096/api/v1/stats?type=full

    GET

    /getExecutionStats?name=[function_name]

    Retrieve only execution statistics. This will return the subset of statistics for the node.

    Sample API:

    curl -XGET http://Administrator:password@192.168.1.5:8096/getExecutionStats?name=[function_name]

    GET

    /getLatencyStats?name=[function_name]

    Retrieve only latency statistics. This will return the subset of statistics for the node.

    Sample API:

    curl -XGET http://Administrator:password@192.168.1.5:8096/getLatencyStats?name=[function_name]

    GET

    /getFailureStats?name=[function_name]

    Retrieve only failure statistics. This will return the subset of statistics for the node.

    Sample API:

    curl -XGET http://Administrator:password@192.168.1.5:8096/getFailureStats?name=[function_name]
    Table 7. Eventing Functions API (deprecated activation/deactivation)
    HTTP Method URI Path Description

    POST

    /api/v1/functions/[function_name]/settings

    Deploys an undeployed Function or resumes a paused function from its paused DCP checkpoint. Deprecated, see (basic activation/deactivation) for preferred invocation. A deploy/resume CURL example is provided for reference.

    Sample API:

    curl -XPOST -d '{"deployment_status":true,"processing_status":true}' http://Administrator:password@192.168.1.5:8096/api/v1/functions/[sample_name]/settings

    POST

    /api/v1/functions/[function_name]/settings

    Undeploys a Function. Deprecated, see (basic activation/deactivation) for preferred invocation. An undeploy CURL example is provided for reference.

    Sample API:

    curl -XPOST -d '{"deployment_status":false,"processing_status":false}' http://Administrator:password@192.168.1.5:8096/api/v1/functions/[sample_name]/settings

    POST

    /api/v1/functions/[function_name]/settings

    Pauses a Function and creates a DCP checkpoint such that on a subsequent resume no mutations will be lost. Deprecated, see (basic activation/deactivation) for preferred invocation. A pause CURL example is provided for reference.

    Sample API:

    curl -XPOST -d '{"deployment_status":true,"processing_status":false}' http://Administrator:password@192.168.1.5:8096/api/v1/functions/[sample_name]/settings