Functions
Functions are a snippet code that provides better modularity for your extensions. Developers can use these functions for server-side operations. Functions are built in the Deluge script builder, where you can drag-and-drop and create complex functions seamlessly. To know more about functions, click here.
Functions can be executed either independently or via triggers, based on the extension events such as when your extension is installed, uninstalled, or enabled or disabled. If functions are executed via triggers, then the desk automatically identifies the action based on extension installation or extension uninstallation. If functions are executed independently, you can use the execution URL.
This execution URL can be copied from the functions tab provided in the Functions tab respective Extension Details page of Sigma website.
Sample Execution URL:
https://36e62d03-0eef-4ef3-9f3e-123fa3585c44.sigmaexecution.com/workspace/invokefunction?sigma_function_uuid=1a123cae-bc85-4579-847d-9409f97db97c&sigma_function_version=1&integ_scope_id=&app_install_id=&custom_response=true&auth_type=apikey&encapiKey=
Input Data to Function
When you execute a function, it generates the input data as given below:
{
"app_install_id" : "12345678901234",
"zapp_uuid" : "4998cbb4-2b14-4c46-b8fa-1ba2084c2f13",
"version" : 1.0,
"app_scope_id" : "676543",
"integ_scope_id" : "123456", // service team installed org id
"service_app_id" : "22334455667777", // service team's app installed id
"request_method" : "POST",
"sigma_execution_domain" : "4998cbb4-2b14-4c46-b8fa-1ba2084c2f13.sigmaexecution.com",
"service_domain" : "orchetly.zoho.com",
"payload" : ,
"parameters" : { "param1" : "value1", .... etc },
"headers" : { "header1" : "value1", .... etc },
"encapiKey" : "", // this is unique for each installation
}
Parameters | Description |
---|---|
sigma execution domain | This is the Domain from which the function will be executing. Each DCs have different Sigma execution Domains as listed below
* denotes UUID (Universal Unique ID) of an extension |
service_domain | It denotes the service of associated function and it is based on specific DCs. Example: If it is US DC, then the service_domain will be desk.zoho.com |
sigma_function_uuid | Unique ID of the function. |
integ_scope_id | Org Id of desk |
app_install_id | Installation ID of extension in desk |
encapiKey | Encrypted API key, it is used for authentication purposes.You must do url encode when you try on postman. |
payload | Payload is the data passed when calling this function , it supports JSON and XML content types |
Headers | API will allow a maximum of 30 headers including HTTP default headers. These extra headers will be passed to function via input data with property 'headers'. Note: This count 30 can be increased as per requirement. |
Response from Function
The Function response contains Status Code,Content Type,Response Headers and Response Body
Assume variable 'returnObject' is fetched from Function Response.
Description
Status Code | Returns returnObject.statusCode if present, otherwise return 200. |
Content Type | Returns returnObject.contentType if present, otherwise return "application/json". |
Response Headers | returnObject.responseHeaders will be appended if present. |
Response Body | Returns returnObject.message if present. |
You can also return a custom response from a function by following below guidelines
Let "customResponse" be our response Object.
- customResponse should be an Map type.
- customResponse should be one of the valid HTTP Status Code.
- customResponse should be HTTP supported value.
- customResponse should be key-value pair.
Note: If customResponse is invalid , we will not throw errors. Instead, we will set default values.
Sample script to return Custom response from function
entity = Map();
entity.put("id", 12345);
entity.put("name", "tiger");
responseHeaders = Map();// add response headers if any
customResponse = Map();
customResponse.put("statusCode", 201);
customResponse.put("contentType", "application/json");
customResponse.put("responseHeaders", responseHeaders);
customResponse.put("message", entity);
return customResponse;
Success
If the above script is success, the following response will appear:
Status Code: 201
Content Type: application/json
{
"id": 12345,
"name": "tiger"
}
Failure
If the above script is failed, and then the following notification will pop-up
Status Code: 412
Content Type: application/json
{
"message": "Installation not found for given input."
OR
"message": "Installation is in inactive state for given input."
OR
"message": "App Version status is not allow function execution."
etc
}
Status Code: 500
Content Type: application/json
{
"message": "Function execution failed"
}