JS APIs are JS functions to include various ServiceDesk Plus Cloud functionalities in the custom widget you create.
The JS file must be loaded into every widget page where you want to invoke the APIs. Use the following syntax to add the JS file to the widget pages:
Syntax:
JavaScript API
While developing a custom widget, you can use JS API functions to invoke calls to your widget or any third-party application. This page documents the various functions that you can use to build your custom widget and its use cases.
JS APIs must be invoked from the custom widget.
SDP.init()
Initializes the JS SDK and defines utility functions by establishing the connection between the product and the custom widget. This function acts as foundational to establish a connection between the custom widget and other JS APIs to make them visible to users. Other JS APIs will be defined only when the initialization is completed.
Returns:
Promise - Resolved with API Success or Rejected with API Failure
Syntax:
- SDP.init().then(function(response) {
- console.log(response);
- }).catch(function(response) {
- console.log(response);
- });
Sample:
API Call
| Success Response
|
SDP.init().then(function(response) { console.log(response); }).catch(function(response) { console.log(response); });
| { "meta": { "module": "header", "instance": { "appid": "709641411", "appname": "widgetdev", "appdisplayname": "Widget Development" }, "personalization": { "time_zone": "Asia/Kolkata", "time_format": "MMM d, yyyy hh:mm a", "date_format": "MMM d, yyyy" }, "userLanguage": "en", "userLocale": "en_US", "userType": "Technician", "userId": "120747000000232217", "userName": "Widget Development", "userEmail": " widget_dev@sdpdev.onmicrosoft.com", "isSDAdmin": true, "widget": { "id": "120747000002587069", "name": Custom Widget ", "description": "", "custom_widget": { "id": "120747000002587067" } } }, "uniqueID": "78d261d9-65f7-48bc-b10d-84b7e79b1285", "location": "webtab" } |
SDP.invokeUrl (options)
Fetch data from integrated third-party applications. The function is mapped under various option params such as URL, method, headers, params, payload, file-id (not supported for probe-based integrations), connection pathway (probe or connection link). You can invoke 3rd party URLs directly or by using connections/probes. By default, 3rd party URLs are invoked directly if no connection or probe is set.
Parameters:
Name
| Type
| Description
|
options*
| object
| Object which contains API details.
Property
| Type
| Description
| url*
| string
| Indicates the API URL. Encode the URL if it contains space.
| method
| string
| Indicates the method of the API call. By default “post” method is passed.
Supported methods: get, post, put, delete, and patch.
| params
| object
| Indicates the params of the API in key-value format.
| headers
| object
| Indicates the params of the API in key-value format.
| payload
| string
| String to be passed in Request Body.
| is_probe_connection
| boolean
| If set as true, the connection is established through a probe. Used to connect to Intranet sites or to establish a connection between Cloud and On-premise applications.
| connectionLinkName
| string
| Specify the DRE connection link name. Only connections that are installed in the custom widget package can be used here. This will be considered only if “is_probe_connection” property is not true.
| file_id
| long
| Indicates ServiceDesk Plus Cloud File ID. This option is used if an attachment needs to be uploaded to the third-party application. This property is supported only when the “connectionLinkName” is provided.
|
|
* Mandatory parameter
You cannot configure both probe and DRE connection to invoke a third-party application.
Returns:
Promise - Resolved with API Success or Rejected with API Failure.
Syntax:
- SDP.invokeUrl(options).then(function(response) {
- console.log(response);
- }).catch(function(response) {
- console.log(response);
- });
Sample:
API Call
| Success Response
| Failure Response
|
SDP.invokeUrl({ “url”: “https: //api.twitter.com/1.1/statuses/update.json”, “method”: “post”, “params”: { “status”: "SDP and twitter integrated" }, “connectionLinkName”: “twitter” }).then(function(response) { console.log(response); }).catch(function(response) { console.log(response); }); | //Based on 3rd party API
| //Based on 3rd party API
|
Opens a new widget as a pop-up within the custom widget.
Parameters:
Name
| Type
| Description
|
options*
| object
| Object which contains API details.
Property
| Type
| Description
| id*
| long
| Indicates the ID of the widget to be opened.
| name*
| string
| Indicates the name of the widget to be opened.
| title
| string
| Sets the title of the popup. If the title is not passed, the widget name will be set as the popup title.
| data
| object
| Specifies the data to be passed to the widget that is opening.
|
|
* Mandatory parameter
Either ID or name parameters can be specified as an option to open the widget. If both are specified, only ID will be considered.
Returns:
Promise - Resolved with Success or Rejected with Failure.
Syntax:
- SDP.openWidget(options).then(function(response) {
- console.log(response);
- }).catch(function(response) {
- console.log(response);
- });
Sample:
API Call
| Success Response
| Failure Response
|
SDP.openWidget({ id: "100000000000032273", data: { mode: "new_user" } }).then(function(response) { console.log(response); }).catch(function(response) { console.log(response); }); | {
message: “Widget opened successfully”
}
| {
"message": "Please provide a valid widget id or name with required visibility permissions to render"
}
|
Closes the pop-up where the custom widget is loaded. This API is functional only if a widget is opened in a pop-up window, such as menu widget or a widget opened using the SDP.openWidget API.
Returns:
Promise - Resolved with Success or Rejected with Failure.
Syntax:
- SDP.closeWidget().catch(function(response) {
- console.log(response);
- });
SDP.closeWidget() call’s successful execution closes the widget popup in the window. Hence success callback is not needed for this API.
Sample:
API Call
| Failure Response
|
SDP.closeWidget().catch(function(response) {
console.log(response);
});
| {
message: “This requested action is not supported in this view”
}
|
Resize the custom widget popup as needed. The maximum widget size allowed is 1200X800 pixels.
This API is functional only if a widget is opened in a pop-up window, such as menu widget or a widget opened using the SDP.openWidget API.
Parameters:
Name
| Type
| Description
|
options*
| object
| Object which contains API details.
Property
| Type
| Description
| width*
| integer
| Specify the required widget popup width in pixels. The maximum width for pop-up is 1200 pixels.
| height*
| integer
| Specify the required widget popup height in pixels. Maximum height for pop-up is 800 pixels.
|
|
* Mandatory parameter
Either ID or name parameters can be specified as an option to open the widget. If both are specified, only ID will be considered.
Returns:
Promise - Resolved with Success or Rejected with Failure.
Syntax:
- SDP.resizeWidget(options).then(function(response) {
- console.log(response);
- }).catch(function(response) {
- console.log(response);
- });
Sample:
API Call
| Success Response
| Failure Response
|
SDP.resizeWidget({
width: 1000,
height: 500
}).then(function(response) {
console.log(response);
}).catch(function(response) {
console.log(response);
});
| {
"message": "Window resized successfully"
}
| {
"message": "width is not a valid number"
}
|
Related Articles
Scanned Software
AssetExplorer Cloud monitors all software in the organization, eliminating security threats and optimizing software usage. AssetExplorer Cloud scans your network to identify the software installed on workstations and manages software licenses, ...
Software Licenses
AssetExplorer Cloud allows you to customize license types for all software manufacturers based on the number of workstations and users. The default software license types in AssetExplorer Cloud are as follows: Software License Type Explanation ...
View Software Details
To view the software details, go to Assets > Software > Scanned Software. On the list view, click the software name to open the details page. In the software details page, the right pane displays the software type, installation summary, and license ...
Associate Assets or Software
Assets and software managed by a contract can be associated with the contract. Role Required: SDAdmin, Users with Edit permissions You can associate assets and software licenses while creating a contract. Alternatively, you can also add associations ...
Custom Widgets
Custom Widgets bring external services inside AssetExplorer Cloud and extend the capabilities of the application. Widgets are embeddable UI components that you can create on your own by using JS Software Development Kit. Custom widgets allow you to ...