Manage Variables/Connection in Custom Widget

Manage Variables/Connection in Custom Widget

SDP.getVariables() 

Fetches all the variables associated with the custom widget.

Returns:
Promise - Resolved with Success or Rejected with Failure.

Syntax:
  1. SDP.getVariables().then(function(response) {
  2. console.log(response);
  3. }).catch(function(response) {
  4. console.log(response);
  5. });
 
Sample:
API Call
Success Response
SDP.getVariables().then(function(response) {
console.log(response);
}).catch(function(response) {
console.log(response);
});
[
{
  "id": "100000000000032357",
  "type": "string",
  "secure": false,
  "value": "admin",
  "key": "Username"
}
]
 

SDP.getVariable(key) 

Fetches the details of a specified variable from the widget.

Parameters:
Name
Type
Description
key*
String
Indicates the key of variable whose details are to be fetched.
* - Mandatory parameter

Returns:
Promise - Resolved with Success or Rejected with Failure.

Syntax:
  1. SDP.getVariable(key).then(function(response) {
  2. console.log(response);
  3. }).catch(function(response) {
  4. console.log(response);
  5. });
 
Sample:
API Call
Success Response
Failure Response
SDP.getVariable(“admin”).then(function(response) {
console.log(response);
}).catch(function(response) {
console.log(response);
});
{
"id": "100000000000032357",
"type": "string",
"secure": false,
"value": "john-doe",
"key": "admin"
}
{
"message": "There's no variable available with the provided key"
}
 

SDP.setVariable(key, value) 

Update the value of a variable associated with the widget.
This function is especially useful in Configuration Widgets since they do not have a configuration page in the UI where the variable value can be updated. 

Parameters:
Name
Type
Description
key*
String
Indicates the key of variable to be updated.
value
-
Indicated the value to be updated to the variable. If not passed, the variable value will be reset in application.
* - Mandatory parameter

Returns:
Promise - Resolved with Success or Rejected with Failure.

Syntax:
  1. SDP.setVariable(key, value).then(function(response) {
  2. console.log(response);
  3. }).catch(function(response) {
  4. console.log(response);
  5. });
 
Sample:
API Call
Success Response
Failure Response
SDP.setVariable(“admin”, “john-doe”).then(function(response) {
console.log(response);
}).catch(function(response) {
console.log(response);
});
{
"id": "100000000000032357",
"type": "string",
"secure": false,
"value": "john-doe",
"key": "admin"
}
{
    "response_status": {
        "status_code": 4000,
        "messages": [
            {
                "status_code": 4001,
                "field": "value",
                "error_xpath": "variable.value",
                "type": "failed",
                "message": "Value given for value is not valid"
            }
        ],
        "status": "failed"
    }
}
 

SDP.getTempVariables()

Fetches all temporary variables relevant to the custom widget that are stored in browser where the ServiceDesk Plus MSP Cloud window is opened.
Temporary variables are used to store values for a limited time, such as until the window reloads.

Returns:
Promise - Resolved with Success or Rejected with Failure.

Syntax:
  1. SDP.getTempVariables().then(function(response) {
  2. console.log(response);
  3. }).catch(function(response) {
  4. console.log(response);
  5. });
 
Sample:
API Call
Success Response
SDP.getTempVariables().then(function(response) {
console.log(response);
}).catch(function(response) {
console.log(response);
});
{
    "passphrase": "*****"
}
 

SDP.getTempVariable(key)

Fetches the specified temporary variable.

Parameters:
Name
Type
Description
key*
String
Indicates the temporary variable key that specifies which variable details are to be fetched.
* - Mandatory parameter

Returns:
Promise - Resolved with Success or Rejected with Failure.

Syntax:
  1. SDP.getTempVariable(key).then(function(response) {
  2. console.log(response);
  3. }).catch(function(response) {
  4. console.log(response);
  5. });
 
Sample:
API Call
Success Response
SDP.getTempVariable(“passphrase).then(function(response) {
console.log(response);
}).catch(function(response) {
console.log(response);
});
{
    "key": "passphrase",
    "value": "*****"
}
 

SDP.setTempVariable(key,value)

Set a temporary variable and specify a value to it.

Parameters:
Name
Type
Description
key*
String
The key of the temporary variable to be updated.
value
-
The new value to be configured with the temporary variable.
* - Mandatory parameter

Returns:
Promise - Resolved with Success or Rejected with Failure.

Syntax:
  1. SDP.setTempVariable(key, value).then(function(response) {
  2. console.log(response);
  3. }).catch(function(response) {
  4. console.log(response);
  5. });
 
Sample:
API Call
Success Response
SDP.setTempVariable(“passphrase, “*****”).then(function(response) {
console.log(response);
}).catch(function(response) {
console.log(response);
});
{
    "message": "Variable saved in application window successfully"
}
 

SDP.getConnections() 

Fetches the details of all successfully installed connections that are associated with the widget.
 
Returns:
Promise - Resolved with Success or Rejected with Failure.

Syntax:
  1. SDP.getConnections().then(function(response) {
  2. console.log(response);
  3. }).catch(function(response) {
  4. console.log(response);
  5. });
 
Sample:
API Call
Success Response
SDP.getConnections().then(function(response) {
console.log(response);
}).catch(function(response) {
console.log(response);
});
{
"connections": [
{
"authorize_url": "/delugeauth/authenticateConnections/Public__15459854__15421476__1000000000897261",
"scopeDisplayString": "read, write, account",
"serviceNumber": 104,
"dbName": "Public",
"groupScopeId": "1000000000118063",
"admin": true,
"linkName": "2c3d9619-bcea-459d-a1c8-b3b76c393fb9-15459854-trello",
"revoke_url": "/delugeauth/revokeConnectionApi?sharedBy=15459854&connectionLinkName=2c3d9619-bcea-459d-a1c8-b3b76c393fb9-15459854-trello&isUserDefined=false&zohoServiceName=SDPOnDemand",
"scope_details": [
{
"Scope Name": "read",
"Scope Value": "read"
}
],
"scope": [
"read"
],
"logo": "trello.png",
"connectedServiceId": "1000000000897261",
"absolute_logo_url": "https://js.zohostatic.com/dre/images/connections/logos/trello.png",
"displayLinkName": "2c3d9619-bcea-459d-a1c8-b3b76c393fb9-15459854-trello",
"serviceName": "Trello",
"connected": false,
"versionId": "1000000000118047",
"scoped": true,
"adminZuId": 15421476,
"sharedBy": 15459854,
"userAccess": false,
"connectionName": "Automation Widget-trello",
"isUserDefinedService": false,
"status": 2,
"serviceLinkName": "trello"
}
],
"status": true
}
 

SDP.getConnection(connectionLinkName)

Fetches the details of a specific connection that is associated with the widget.

Parameters:
Name
Type
Description
connectionLinkName*
String
Specifies which connection details are to be fetched.
* - Mandatory parameter

Returns:
Promise - Resolved with Success or Rejected with Failure.

Syntax:
  1. SDP.getConnection(connectionLinkName).then(function(response) {
  2. console.log(response);
  3. }).catch(function(response) {
  4. console.log(response);
  5. });
 
Sample:
API Call
Success Response
Failure Response
SDP.getConnection(“trello).then(function(response) {
console.log(response);
}).catch(function(response) {
console.log(response);
});
{
"connections": {
"authorize_url": "/delugeauth/authenticateConnections/Public__15459854__15421476__1000000000897261",
"scopeDisplayString": "read, write, account",
"serviceNumber": 104,
"dbName": "Public",
"groupScopeId": "1000000000118063",
"admin": true,
"linkName": "2c3d9619-bcea-459d-a1c8-b3b76c393fb9-15459854-trello",
"revoke_url": "/delugeauth/revokeConnectionApi?sharedBy=15459854&connectionLinkName=2c3d9619-bcea-459d-a1c8-b3b76c393fb9-15459854-trello&isUserDefined=false&zohoServiceName=SDPOnDemand",
"scope_details": [
{
"Scope Name": "read",
"Scope Value": "read"
}
],
"scope": [
"read"
],
"logo": "trello.png",
"connectedServiceId": "1000000000897261",
"absolute_logo_url": "https://js.zohostatic.com/dre/images/connections/logos/trello.png",
"displayLinkName": "2c3d9619-bcea-459d-a1c8-b3b76c393fb9-15459854-trello",
"serviceName": "Trello",
"connected": false,
"versionId": "1000000000118047",
"scoped": true,
"adminZuId": 15421476,
"sharedBy": 15459854,
"userAccess": false,
"connectionName": "Automation Widget-trello",
"isUserDefinedService": false,
"status": 2,
"serviceLinkName": "trello"
},
"status": true
}
{
"response_status": {
"status_code": 4000,
"messages": [
{
"status_code": 4001,
"type": "failed",
"message": "No Connection available in the given link name"
}
],
"status": "failed"
}
}
 

SDP.authorizeConnection(connectionLinkName) 

Authorizes the widget's connection by generating a token to the DRE (Deluge Runtime Environment) server. By default, users with permissible roles can authorize connections from the Setup. However, any user can use this JS API to authorize a widget's connection if they don't have access to Setup.
To fetch the post-authorization status, use an event listener to confirm if the authorization is complete

Parameters:
Name
Type
Description
connectionLinkName*
String
Specifies the connection to be authorized.
* - Mandatory parameter

Returns:
Promise - Resolved with Success or Rejected with Failure.

Syntax:
  1. SDP.authorizeConnection(connectionLinkName).then(function(response) {
  2. console.log(response);
  3. }).catch(function(response) {
  4. console.log(response);
  5. });
 
Sample:
API Call
Success Response
Failure Response
SDP.authorizeConnection(“trello”).then(function(response) {
console.log(response);
}).catch(function(response) {
console.log(response);
});
{
"connections": {
"authorize_url": "/delugeauth/authenticateConnections/Public__15459854__15421476__1000000000897261",
"scopeDisplayString": "read, write, account",
"serviceNumber": 104,
"dbName": "Public",
"groupScopeId": "1000000000118063",
"admin": true,
"linkName": "2c3d9619-bcea-459d-a1c8-b3b76c393fb9-15459854-trello",
"revoke_url": "/delugeauth/revokeConnectionApi?sharedBy=15459854&connectionLinkName=2c3d9619-bcea-459d-a1c8-b3b76c393fb9-15459854-trello&isUserDefined=false&zohoServiceName=SDPOnDemand",
"scope_details": [
{
"Scope Name": "read",
"Scope Value": "read"
}
],
"scope": [
"read"
],
"logo": "trello.png",
"connectedServiceId": "1000000000897261",
"absolute_logo_url": "https://js.zohostatic.com/dre/images/connections/logos/trello.png",
"displayLinkName": "2c3d9619-bcea-459d-a1c8-b3b76c393fb9-15459854-trello",
"serviceName": "Trello",
"connected": false,
"versionId": "1000000000118047",
"scoped": true,
"adminZuId": 15421476,
"sharedBy": 15459854,
"userAccess": false,
"connectionName": "Automation Widget-trello",
"isUserDefinedService": false,
"status": 2,
"serviceLinkName": "trello"
},
"status": true
}
{
"response_status": {
"status_code": 4000,
"messages": [
{
"status_code": 4001,
"type": "failed",
"message": "No Connection available in the given link name"
}
],
"status": "failed"
}
}
 

SDP.revokeConnection(connectionLinkName)

Revokes the widget's connection.

To fetch the status post revoking the connection, use an event listener to confirm if the revoke was complete.

Parameters:
Name
Type
Description
connectionLinkName*
String
Specifies the connection to be revoked.
* - Mandatory parameter

Returns:
Promise - Resolved with Success or Rejected with Failure.

Syntax:
  1. SDP.revokeConnection(connectionLinkName).then(function(response) {
  2. console.log(response);
  3. }).catch(function(response) {
  4. console.log(response);
  5. });
 
Sample:
API Call
Success Response
Failure Response
SDP.revokeConnection(“trello).then(function(response) {
console.log(response);
}).catch(function(response) {
console.log(response);
});
{
    "response": "Connection revoked successfully"
}
{
    "response_status": {
        "status_code": 4000,
        "messages": [
            {
                "status_code": 4004,
                "type": "failed",
                "message": "Connection revoked already"
            }
        ],
        "status": "failed"
    }
}