Migrating Functions
If you are using functions inside Marketplace, you need to migrate those existing functions to Sigma before publishing any of your extensions on the Sigma website to support multiDC. You can migrate easily, as both the Marketplace and Sigma use Deluge for code scripting.
This migration process involves three changes, that are to
Get domains dynamically
You need to get the domains dynamically by using extra keys such as service_domain and sigma_domain.
Function inside Marketplace
deskurl = "https://desk.zoho.com";
sigmaurl = "https://sigma.zoho.com"
Function inside Sigma
deskurl = data.get("service_domain"); // desk.zoho.com
sigmaurl = data.get("sigma_domain"); // sigma.zoho.com
Invoke an API from functions
Simply invoke the API directly with the required parameters as shown in the following snippet, unlike Marketplace function where you need to construct form data, headerMap, hash, and more.
Function inside Marketplace
deskurl = "https://desk.zoho.com";
connectionLinkName = "connectionLinkName";
secret = "*******";
orgId = data.get("queryParams").get("orgId");
securityContext = data.get("queryParams").get("securityContext");
formdata = Map();
formdata.put("requestType", "get");
formdata.put("connectionLinkName", connectionLinkName);
formdata.put("requestURL", deskurl + "/api/v1/installedExtensions/{{installationId}}/storage?orgId
=" + orgId + "&queriableValue=apps&limit=99"
reqUrl = formdata.get("requestURL");
tobehashed = "requestURL="+ reqUrl + "&requestType=get&connectionLinkName=" + connectionLinkName;
hash = zoho.encryption.hmacsha256(secret, tobehashed, "hex");
headersMap = Map();
logsMap = Map();
logsMap.put("title", "Fetch apps");
headersMap.put("logs", logsMap.toString());
headersMap.put("HASH", hash.toString());
storageRes = invokeurl
[
url : deskurl + "/api/v1/invoke?orgId=" + orgId + "&securityContext=" + securityContext
type: POST
parameters: formdata
headers: headersMap
];
Function inside Sigma
deskurl = data.get("service_domain");
installationId = data.get("service_app_id");
storageRes = invokeurl
[
url : deskurl + "/api/v1/installedExtensions/" + installationId + "/storage?queriableValue=apps&limit=99"
type: GET
connection: "connectionLinkName"
];
Note: For functions inside Marketplace, there is no need to make a separate API call for extension logging. During this migration, you have to make separate API calls.
Fetch API Response directly
The response for the corresponding API is fetched directly in a single iteration for functions inside Sigma, whereas in Marketplace it involves nested iterations.
Function inside Marketplace
dbObject = storageRes.get("response").get("statusMessage");
apps = dbObject.get("data");
Function inside Sigma
apps = storageRes.get("data");