UNPKG

dctrackclient

Version:

Sunbird dcTrack API client in JavaScript

1,263 lines (1,118 loc) 55.6 kB
import fetch from 'node-fetch'; import { HttpsProxyAgent } from 'https-proxy-agent'; import { SocksProxyAgent } from 'socks-proxy-agent'; /** * Sunbird dcTrack API client version 1.4.6 in JavaScript */ export class Client { #base_url; #username; #password; #apiToken; #proxyAgent; /** * Provide either a username and password, or an API token to access the dcTrack database with JavaScript. */ constructor(base_url = '', credentials = { username: '', password: '', apiToken: '' }, proxy = { https: '', socks: '' }) { this.#base_url = base_url; this.#username = credentials.username; this.#password = credentials.password; this.#apiToken = credentials.apiToken; if (proxy.https) { this.#proxyAgent = new HttpsProxyAgent(proxy.https); } else if (proxy.socks) { this.#proxyAgent = new SocksProxyAgent(proxy.socks); } } /** * Generate and return an API token. */ async generateToken() { if (this.#username && this.#password && !this.#apiToken) { return (await fetch(this.#base_url + '/api/v2/authentication/login', { method: 'POST', agent: this.#proxyAgent, headers: [['Authorization', 'Basic ' + btoa(this.#username + ':' + this.#password)]] })).headers.get('Authorization').split(' ')[1]; } else { throw new Error('Username/password undefined or token predefined.'); } } /** * @private Internal class method. */ async request(method = '', endpoint = '', body = undefined) { if (!this.#apiToken) { this.#apiToken = await this.generateToken(); } return (await fetch(this.#base_url + '/' + endpoint, { method: method, agent: this.#proxyAgent, headers: [['Authorization', 'Bearer ' + this.#apiToken], ['Content-Type', 'application/json']], body: JSON.stringify(body) })).json().catch(() => ({})); } } /** * Get item details using the item ID. Returns an Item JSON object. * @param {number} id */ Client.prototype.getItem = function (id) { return this.request('GET', '/api/v2/dcimoperations/items/' + id + '?'); } /** * Create a new item. When returnDetails is set to true, the API call will return the full json payload. If set to false, the call returns only the "id" and "tiName". Returns the newly created item JSON object. * @param {boolean} returnDetails * @param {boolean} proceedOnWarning * @param {object} payload */ Client.prototype.createItem = function (returnDetails, proceedOnWarning, payload) { return this.request('POST', '/api/v2/dcimoperations/items?returnDetails=' + returnDetails + '&proceedOnWarning=' + proceedOnWarning + '&', payload); } /** * Update an existing item. When returnDetails is set to true, the API call will return the full json payload. If set to false, the call returns only the "id" and "tiName". * @param {number} id * @param {boolean} returnDetails * @param {boolean} proceedOnWarning * @param {object} payload */ Client.prototype.updateItem = function (id, returnDetails, proceedOnWarning, payload) { return this.request('PUT', '/api/v2/dcimoperations/items/' + id + '?returnDetails=' + returnDetails + '&proceedOnWarning=' + proceedOnWarning + '&', payload); } /** * Delete an item using the item ID. * @param {number} id * @param {boolean} proceedOnWarning */ Client.prototype.deleteItem = function (id, proceedOnWarning) { return this.request('DELETE', '/api/v2/dcimoperations/items/' + id + '?proceedOnWarning=' + proceedOnWarning + '&'); } /** * Search for items using criteria JSON object. Search criteria can be any of the fields applicable to items, including custom fields. Specify the fields to be included in the response. This API supports pagination. Returns a list of items with the specified information. * @param {number} pageNumber * @param {number} pageSize * @param {object} payload */ Client.prototype.searchItems = function (pageNumber, pageSize, payload) { return this.request('POST', '/api/v2/quicksearch/items?pageNumber=' + pageNumber + '&pageSize=' + pageSize + '&', payload); } /** * Returns a list of Items contained in a Cabinet using the ItemID of the Cabinet. The returned list includes all of the Cabinet's Items including Passive Items. * @param {number} CabinetId */ Client.prototype.getCabinetItems = function (CabinetId) { return this.request('GET', '/api/v2/items/cabinetItems/' + CabinetId + '?'); } /** * Add/Update/Delete Items. * @param {object} payload */ Client.prototype.createItemsBulk = function (payload) { return this.request('POST', '/api/v2/dcimoperations/items/bulk?', payload); } /** * Returns a list of makes with basic information. */ Client.prototype.getMakes = function () { return this.request('GET', '/api/v2/makes?'); } /** * Add a new Make. Returns JSON entity containing Make information that was passed in from the Request payload. * @param {object} payload */ Client.prototype.createMake = function (payload) { return this.request('POST', '/api/v2/makes?', payload); } /** * Modify a Make. Returns JSON entity containing Make information that was passed in from the Request payload. * @param {number} makeId * @param {object} payload */ Client.prototype.updateMake = function (makeId, payload) { return this.request('PUT', '/api/v2/makes/' + makeId + '?', payload); } /** * Delete a Make. * @param {number} makeId */ Client.prototype.deleteMake = function (makeId) { return this.request('DELETE', '/api/v2/makes/' + makeId + '?'); } /** * Search for a make using the make name. Returns a list of makes with basic information. * @param {string} makeName */ Client.prototype.getMakesByName = function (makeName) { return this.request('GET', '/api/v2/dcimoperations/search/makes/' + makeName + '?'); } /** * Get Model fields for the specified Model ID. usedCounts is an optional parameter that determines if the count of Items for the specified model is returned in the response. If set to "true" the counts will be included in the response, if omitted or set to "false" the item count will not be included in the response. * @param {number} modelId * @param {boolean} usedCounts */ Client.prototype.getModel = function (modelId, usedCounts) { return this.request('GET', '/api/v2/models/' + modelId + '?usedCounts=' + usedCounts + '&'); } /** * Add a new Model. Returns JSON entity containing Make information that was passed in from the Request payload. "proceedOnWarning" relates to the warning messages that are thrown in dcTrack when you try to delete custom fields that are in use. The "proceedOnWarning" value can equal either "true" or "false." If "proceedOnWarning" equals "true," business warnings will be ignored. If "proceedOnWarning" equals "false," business warnings will not be ignored. Fields that are not in the payload will remain unchanged. * @param {boolean} returnDetails * @param {boolean} proceedOnWarning * @param {object} payload */ Client.prototype.createModel = function (returnDetails, proceedOnWarning, payload) { return this.request('POST', '/api/v2/models?returnDetails=' + returnDetails + '&proceedOnWarning=' + proceedOnWarning + '&', payload); } /** * Modify an existing Model. Fields that are not in the payload will remain unchanged. Returns a JSON entity containing Make information that was passed in from the Request payload. This API performs as a PUT and not a PATCH. For example, the Request includes the dataPorts list but nothing inside it, the data ports will be removed, or you include a new port in the list , but not the current port on the device, it will remove the port that already exists and create a new port. * @param {number} id * @param {boolean} returnDetails * @param {boolean} proceedOnWarning * @param {object} payload */ Client.prototype.updateModel = function (id, returnDetails, proceedOnWarning, payload) { return this.request('PUT', '/api/v2/models/' + id + '?returnDetails=' + returnDetails + '&proceedOnWarning=' + proceedOnWarning + '&', payload); } /** * Modify an existing Model. This is currently being released as a Beta version for early release and is subject to change. * @param {number} id * @param {boolean} returnDetails * @param {boolean} proceedOnWarning * @param {object} payload */ Client.prototype.modifyModel = function (id, returnDetails, proceedOnWarning, payload) { return this.request('PATCH', '/api/v2/models/' + id + '?returnDetails=' + returnDetails + '&proceedOnWarning=' + proceedOnWarning + '&', payload); } /** * Delete a Model using the Model ID. * @param {number} id */ Client.prototype.deleteModel = function (id) { return this.request('DELETE', '/api/v2/models/' + id + '?'); } /** * Search for models by user supplied search criteria. Returns a list of models with the "selectedColumns" returned in the payload. Search by Alias is not supported. * @param {number} pageNumber * @param {number} pageSize * @param {object} payload */ Client.prototype.searchModels = function (pageNumber, pageSize, payload) { return this.request('POST', '/api/v2/quicksearch/models?pageNumber=' + pageNumber + '&pageSize=' + pageSize + '&', payload); } /** * Delete a Mode Image using the Model ID and the Image Orientation, where id is the Model Id and orientation is either front or back * @param {number} id * @param {string} orientation */ Client.prototype.deleteModelImage = function (id, orientation) { return this.request('DELETE', '/api/v2/models/images/' + id + '/' + orientation + '?'); } /** * Get a Connector record by ID. Returns a Connector with all information including Compatible Connectors. The usedCount parameter is optional. If usedCount is true, the response will include the number of times the connector is in use by Models and Items. If false, no counts are returned. If omitted the default is false. * @param {number} connectorId * @param {boolean} usedCount */ Client.prototype.getConnector = function (connectorId, usedCount) { return this.request('GET', '/api/v2/settings/connectors/' + connectorId + '?usedCount=' + usedCount + '&'); } /** * Add a new Connector. Returns JSON entity containing Connector information that was passed in from the Request payload. * @param {object} payload */ Client.prototype.createConnector = function (payload) { return this.request('POST', '/api/v2/settings/connectors?', payload); } /** * Update an existing Connector. Returns JSON entity containing Connector information that was passed in from the Request payload. * @param {number} connectorId * @param {object} payload */ Client.prototype.updateConnector = function (connectorId, payload) { return this.request('PUT', '/api/v2/settings/connectors/' + connectorId + '?', payload); } /** * Delete one or more Connector records. * @param {object} payload */ Client.prototype.removeConnector = function (payload) { return this.request('POST', '/api/v2/settings/connectors/delete?', payload); } /** * Search for Connectors using criteria JSON object. Search criteria can be any of the fields applicable to Connector, including custom fields. Specify the fields to be included in the response. This API supports pagination. Returns a list of Connectors with the specified information. * @param {number} pageNumber * @param {number} pageSize * @param {object} payload */ Client.prototype.searchConnectors = function (pageNumber, pageSize, payload) { return this.request('POST', '/api/v2/quicksearch/connectors?pageNumber=' + pageNumber + '&pageSize=' + pageSize + '&', payload); } /** * Delete a Connector Image using the Connector ID. * @param {number} connectorId */ Client.prototype.deleteConnectorImage = function (connectorId) { return this.request('DELETE', '/api/v2/settings/connectors/' + connectorId + '/images?'); } /** * Use the REST API to retrieve details from all data ports on an item. If the operation was successful, a status code 200 is displayed, and the body contains the item's data port details. If the operation failed, an error code is returned. * @param {number} itemId */ Client.prototype.getDataPorts = function (itemId) { return this.request('GET', '/api/v1/items/' + itemId + '/dataports?'); } /** * Use the REST API to read the details of an item's data port. To do this, specify the item and item data port ID. If the operation was successful, a status code 200 is displayed, and the body contains the item's data port details. If the operation failed, an error code is returned. * @param {number} itemId * @param {number} dataportId */ Client.prototype.getDataPort = function (itemId, dataportId) { return this.request('GET', '/api/v1/items/' + itemId + '/dataports/' + dataportId + '?'); } /** * Use the REST API to create data ports for an existing item. If ports are already defined for the item because it is included in the Item Models Library, you can use the REST API to create additional ports for the item. Payload contains data port parameter details in json format. All required fields must be included. * @param {number} itemId * @param {object} payload */ Client.prototype.createDataPorts = function (itemId, payload) { return this.request('POST', '/api/v1/items/' + itemId + '/dataports?', payload); } /** * Update an item's data port details using the REST API. To do this, specify the item and data port ID, and provide the updated parameter value(s). Payload contains data port parameter details in json format. All required fields must be included. * @param {number} itemId * @param {number} dataportId * @param {object} payload */ Client.prototype.updateDataPort = function (itemId, dataportId, payload) { return this.request('PUT', '/api/v1/items/' + itemId + '/dataports/' + dataportId + '?', payload); } /** * Delete an item's data port using the REST API by specifying the item ID and data port ID. If the operation is successful, a status code 200 is displayed. If the operation failed, an error code is returned. * @param {number} itemId * @param {number} dataportId */ Client.prototype.deleteDataPort = function (itemId, dataportId) { return this.request('DELETE', '/api/v1/items/' + itemId + '/dataports/' + dataportId + '?'); } /** * Use the REST API to retrieve details from all power ports on an item. * @param {number} itemId */ Client.prototype.getPowerPorts = function (itemId) { return this.request('GET', '/api/v1/items/' + itemId + '/powerports?'); } /** * Use the REST API to retrieve details from one power port on an item. * @param {number} itemId * @param {number} portId */ Client.prototype.getPowerPort = function (itemId, portId) { return this.request('GET', '/api/v1/items/' + itemId + '/powerports/' + portId + '?'); } /** * Use the REST API to create power ports for an existing item. If ports are already defined for the item because it is included in the Item Models Library, you can use the REST API to create additional ports for the item. * @param {number} itemId * @param {number} portId * @param {boolean} proceedOnWarning * @param {object} payload */ Client.prototype.updatePowerPort = function (itemId, portId, proceedOnWarning, payload) { return this.request('PUT', '/api/v1/items/' + itemId + '/powerports/' + portId + '?proceedOnWarning=' + proceedOnWarning + '&', payload); } /** * Use the REST API to determine if a Connector is compatible with a specific Power Port. * @param {number} itemId * @param {number} portId * @param {number} connectorId */ Client.prototype.getCompatibleConnector = function (itemId, portId, connectorId) { return this.request('GET', '/api/v1/items/' + itemId + '/powerports/' + portId + '/connectors/' + connectorId + '/isCompatible?'); } /** * Get a list of all Breakers for a given Panel Item. Returns JSON entity containing an array of all the Breakers for the specified Panel Item. * @param {number} panelItemId */ Client.prototype.getBreakers = function (panelItemId) { return this.request('GET', '/api/v2/dcimoperations/items/' + panelItemId + '/breakers?'); } /** * Get a list of all Breakers for a given Panel Item. Returns JSON entity containing information for a single Panel Item Breaker. * @param {number} panelItemId * @param {number} breakerPortId */ Client.prototype.getBreaker = function (panelItemId, breakerPortId) { return this.request('GET', '/api/v2/dcimoperations/items/' + panelItemId + '/breakers/' + breakerPortId + '?'); } /** * Update a single Breaker for a given Panel Item. Returns JSON entity containing information for the updated Panel Item Breaker. Note: This API performs as a true PUT and not a PATCH. Unlike with a PATCH, you must specify all attributes even if you want to change only one. Attributes that are not included in the Request will be considered as removed. * @param {number} panelItemId * @param {number} breakerPortId * @param {object} payload */ Client.prototype.updateBreaker = function (panelItemId, breakerPortId, payload) { return this.request('PUT', '/api/v2/dcimoperations/items/' + panelItemId + '/breakers/' + breakerPortId + '?', payload); } /** * Create a single Breaker for a given Panel Item. Returns JSON entity containing information for the created Panel Item Breaker. Note: Breaker State is set based on the connection status of the Breaker. If the breaker is connected it will always be set to "Closed", even if "Open" is specified in the Request. * @param {number} panelItemId * @param {object} payload */ Client.prototype.createBreaker = function (panelItemId, payload) { return this.request('POST', '/api/v2/dcimoperations/items/' + panelItemId + '/breakers?', payload); } /** * Delete a Breaker for a given Panel Item. Returns empty JSON. * @param {number} panelItemId * @param {number} breakerPortId */ Client.prototype.deleteBreaker = function (panelItemId, breakerPortId) { return this.request('DELETE', '/api/v2/dcimoperations/items/' + panelItemId + '/breakers/' + breakerPortId + '?'); } /** * Add/Update/Delete Breakers for a given Panel Item. * @param {number} panelItemId * @param {object} payload */ Client.prototype.createBreakersBulk = function (panelItemId, payload) { return this.request('POST', '/api/v2/dcimoperations/items/' + panelItemId + '/breakers/bulk?', payload); } /** * Returns a list for all Locations. */ Client.prototype.getLocations = function () { return this.request('GET', '/api/v1/locations?'); } /** * Get a single Location. Returns json containing location data for the specified ID. * @param {number} locationId */ Client.prototype.getLocation = function (locationId) { return this.request('GET', '/api/v1/locations' + locationId + '?'); } /** * Add a Location. Returns the JSON entity containing location info that was passed in. Note: "proceedOnWarning" relates to the warning messages that are thrown in dcTrack when you try to delete custom fields that are in use. The "proceedOnWarning" value can equal either "true" or "false." If "proceedOnWarning" equals "true," business warnings will be ignored. If "proceedOnWarning" equals "false," business warnings will not be ignored. * @param {boolean} proceedOnWarning * @param {object} payload */ Client.prototype.createLocation = function (proceedOnWarning, payload) { return this.request('POST', '/api/v1/locations?proceedOnWarning=' + proceedOnWarning + '&', payload); } /** * Modify Location details for a single Location. Payload contains new location details. You do not have have to provide all details, but only those that you want to modify. Returns JSON entity containing Location information that was passed in from the Request payload. * @param {number} locationId * @param {boolean} proceedOnWarning * @param {object} payload */ Client.prototype.updateLocation = function (locationId, proceedOnWarning, payload) { return this.request('PUT', '/api/v1/locations/' + locationId + '?proceedOnWarning=' + proceedOnWarning + '&', payload); } /** * Delete a Location. * @param {number} locationId */ Client.prototype.deleteLocation = function (locationId) { return this.request('DELETE', '/api/v1/locations/' + locationId + '?'); } /** * Search for Locations by user supplied search criteria. Returns a list of Locations with the "selectedColumns" returned in the payload. * @param {number} pageNumber * @param {number} pageSize * @param {object} payload */ Client.prototype.searchLocations = function (pageNumber, pageSize, payload) { return this.request('POST', '/api/v2/quicksearch/locations?pageNumber=' + pageNumber + '&pageSize=' + pageSize + '&', payload); } /** * Returns a list of all Location fields. */ Client.prototype.getLocationFieldList = function () { return this.request('GET', '/api/v2/quicksearch/locations/locationListFields?'); } /** * Get all sub-locations for a given location in the hierarchy. The locationId is the ID of the location to get the sub-locations for. * @param {number} locationId */ Client.prototype.getSublocations = function (locationId) { return this.request('GET', '/api/v2/subLocations/list/' + locationId + '?'); } /** * Get all sub-locations of given type for a given location in the hierarchy. The locationId is the id of the location you are querying the sub-location types for. The type is one of either 5016 and 5017 for rows and aisles respectively. * @param {number} locationId * @param {string} typeCode */ Client.prototype.getSublocationsOfType = function (locationId, typeCode) { return this.request('GET', '/api/v2/subLocations/' + locationId + '/type/' + typeCode + '?'); } /** * Get all child sub-locations for a given sub-location in the hierarchy. The locationId is the ID of the location to fetch the sub-locations for. The subLocationId is the ID of the parent sub-location that you are querying the children of. * @param {number} subLocationId */ Client.prototype.getChildSublocations = function (subLocationId) { return this.request('GET', '/api/v2/subLocations/' + subLocationId + '/children?'); } /** * Get details for a given sub-location. The subLocationId is the id of the sub-location you are querying for. * @param {number} subLocationId */ Client.prototype.getSublocation = function (subLocationId) { return this.request('GET', '/api/v2/subLocations/' + subLocationId + '?'); } /** * Add a new sub-location to the given location. Returns a list from the Sub-Location Hash. * @param {object} payload */ Client.prototype.createSublocation = function (payload) { return this.request('POST', '/api/v2/subLocations?', payload); } /** * Update a sub-location. Returns a list from the Sub-Location Hash. * @param {number} subLocationId * @param {object} payload */ Client.prototype.updateSublocation = function (subLocationId, payload) { return this.request('PUT', '/api/v2/subLocations/' + subLocationId + '?', payload); } /** * Deletes the given sub-location. The locationId is the ID of the location that the sub-location belongs to and the subLocationId is the ID of the location you are querying. Returns a success message upon success. * @param {number} subLocationId */ Client.prototype.deleteSublocation = function (subLocationId) { return this.request('DELETE', '/api/v2/subLocations/' + subLocationId + '?'); } /** * Retrieve a List of Location Favorites for a specific User. * @param {string} username */ Client.prototype.getLocationFavorites = function (username) { return this.request('GET', '/api/v2/users/' + username + '/favorites/LOCATION?'); } /** * Retrieve a List of Location Favorites for all Users. Returns JSON entity containing Location Favorite information for all users. */ Client.prototype.getLocationFavoritesAllUsers = function () { return this.request('GET', '/api/v2/users/favorites/LOCATION?'); } /** * Assign Location Favorites to a user where username is a valid dcTrack user and "favorite" is either true or false to indicate whether you are assigning or unassigning. JSON entity containing all Location Favorites for the specified user. * @param {string} username * @param {object} payload */ Client.prototype.updateLocationFavorites = function (username, payload) { return this.request('PUT', '/api/v2/users/' + username + '/favorites?', payload); } /** * Assign Location Favorites to a user. To Assign favorites the "favorite" column should be set to true. To Unassign favorites the "favorite" column should be set to false. Returns JSON entity containing all Location Favorites for the specified users. * @param {object} payload */ Client.prototype.updateLocationFavoritesAllUsers = function (payload) { return this.request('PUT', '/api/v2/users/favorites?', payload); } /** * Find Cabinets with available space based on RUs within the specified Locations. * @param {object} payload */ Client.prototype.searchCabinetSpace = function (payload) { return this.request('POST', '/api/v2/capacity/cabinets/list/search?', payload); } /** * Find the starting RUs within a Cabinet with the specified number of contiguous RUs. * @param {object} payload */ Client.prototype.searchAvailableRUs = function (payload) { return this.request('POST', '/api/v2/items/uposition/available?', payload); } /** * Get explicit permission by ID. Returns JSON entity containing Permission information for the specified Permission Id. * @param {number} permissionId */ Client.prototype.getPermission = function (permissionId) { return this.request('GET', '/api/v2/permissions/explicit/' + permissionId + '?'); } /** * Add explicit permission. Returns JSON entity containing Permission information for the added Permission. * @param {object} payload */ Client.prototype.createPermission = function (payload) { return this.request('POST', '/api/v2/permissions/explicit?', payload); } /** * Update explicit permission. Returns JSON entity containing Permission information for the updated Permission. * @param {number} permissionId * @param {object} payload */ Client.prototype.updatePermission = function (permissionId, payload) { return this.request('PUT', '/api/v2/permissions/explicit/' + permissionId + '?', payload); } /** * Delete explicit permission. * @param {number} permissionId */ Client.prototype.deletePermission = function (permissionId) { return this.request('DELETE', '/api/v2/permissions/explicit/' + permissionId + '?'); } /** * Add/Update/Delete explicit permissions. * @param {object} payload */ Client.prototype.createPermissionsBulk = function (payload) { return this.request('POST', '/api/v2/permissions/explicit/bulk?', payload); } /** * Get all explicit permissions. Returns JSON entity containing Permission information. */ Client.prototype.getPermissions = function () { return this.request('GET', '/api/v2/permissions/explicit?'); } /** * Get explicit permissions by Entity Type. Returns JSON entity containing Permission information. * @param {string} entityType */ Client.prototype.getPermissionsByEntityType = function (entityType) { return this.request('GET', '/api/v2/permissions/explicit/entityType/' + entityType + '?'); } /** * Get explicit permissions by Entity Type and Entity ID. Returns JSON entity containing Permission information. * @param {string} entityType * @param {number} entityId */ Client.prototype.getPermissionsByEntityId = function (entityType, entityId) { return this.request('GET', '/api/v2/permissions/explicit/' + entityType + '/' + entityId + '?'); } /** * Get a list of records (options) for use in drop-down lists by indicating a list type and an ID. ID is optional for some list types. Returns a list of records for a given list type. * @param {string} listType * @param {number} id */ Client.prototype.getRecords = function (listType, id) { return this.request('GET', '/api/v2/dcimoperations/lookups/' + listType + '/' + id + '?'); } /** * Get a list of records (options) for use in drop-down lists for dcTrack standard fields by list type. Returns a list of records for a given list type. * @param {string} listType */ Client.prototype.getPicklistOptions = function (listType) { return this.request('GET', '/api/v2/dcimoperations/picklists/' + listType + '?'); } /** * Update a list of records (options) for use in drop-down lists for dcTrack standard fields by list type. Returns a list of records for a given list type. * @param {string} listType * @param {object} payload */ Client.prototype.updatePicklistOptions = function (listType, payload) { return this.request('PUT', '/api/v2/dcimoperations/picklists/' + listType + '?', payload); } /** * Update the default value for a picklist field. * @param {object} payload */ Client.prototype.updateDefaultValue = function (payload) { return this.request('PUT', '/api/v2/settings/lists/defaultValue?', payload); } /** * Get the properties for all fields applicable to the Entity. * @param {string} entity */ Client.prototype.getFieldProperties = function (entity) { return this.request('GET', '/api/v2/settings/lists/fieldProperties?entity=' + entity + '&'); } /** * Create a request. * @param {object} payload */ Client.prototype.createRequest = function (payload) { return this.request('POST', '/api/v2/dcimoperations/requests?', payload); } /** * Cancel a request. Returns Returns request ID canceled. * @param {number} requestId */ Client.prototype.deleteRequest = function (requestId) { return this.request('DELETE', '/api/v2/dcimoperations/requests/' + requestId + '?'); } /** * Add/Update/Delete Requests in Bulk. The body of the Request should contain the required fields required to perform the specified Method. Returns JSON entity containing data for the Requests. * @param {object} payload */ Client.prototype.createRequestBulk = function (payload) { return this.request('POST', '/api/v2/dcimoperations/requests/bulk?', payload); } /** * Change request status/stage to Complete using the request ID. Optionally, pass a request body with additional information. Returns request status information. * @param {number} requestId * @param {object} payload */ Client.prototype.completeRequest = function (requestId, payload) { return this.request('PUT', '/api/v2/dcimoperations/requests/complete/' + requestId + '?', payload); } /** * Complete work order and change work order status/stage to Complete. Optionally, pass a request body with additional information. Returns work order status information. * @param {number} workOrderId * @param {object} payload */ Client.prototype.completeWorkOrder = function (workOrderId, payload) { return this.request('PUT', '/api/v2/dcimoperations/workorders/complete/' + workOrderId + '?', payload); } /** * Get a list of pending request status information for a given item ID. Returns list of request status. * @param {number} itemId */ Client.prototype.getRequestStatusByItem = function (itemId) { return this.request('GET', '/api/v2/dcimoperations/requests/pending/' + itemId + '?'); } /** * Get request status information for a given request ID. Returns full request status information. * @param {number} requestId */ Client.prototype.getRequest = function (requestId) { return this.request('GET', '/api/v2/dcimoperations/requests/status/' + requestId + '?'); } /** * Get request status information for a given request ID. Returns full request status information. * @param {object} payload */ Client.prototype.searchRequests = function (payload) { return this.request('POST', '/api/v2/dcimoperations/search/list/requests?', payload); } /** * Create a data connection. Returns the newly created data connection. * @param {object} payload */ Client.prototype.createDataConnection = function (payload) { return this.request('POST', '/api/v2/connections/dataconnections?', payload); } /** * Edit a data connection. Returns the newly edited data connection. * @param {number} connectionId * @param {object} payload */ Client.prototype.updateDataConnection = function (connectionId, payload) { return this.request('PUT', '/api/v2/connections/dataconnections/' + connectionId + '?', payload); } /** * Get a data connection and associated details. Requires the ID of the connection you want to retrieve. Returns the requested data connection and associated details. * @param {number} connectionId */ Client.prototype.getDataConnection = function (connectionId) { return this.request('GET', '/api/v2/connections/dataconnections/' + connectionId + '?'); } /** * Get data connection details based on the specified location, item name, and port name. The itemName specified in the URL must be either the starting or ending Item in the connection. This API does not support Data Panel Ports. Returns the JSON payload with the requested data connection details. * @param {string} location * @param {string} itemName * @param {string} portName */ Client.prototype.getDataConnectionByNode = function (location, itemName, portName) { return this.request('GET', '/api/v2/connections/dataconnections?location=' + location + '&itemName=' + itemName + '&portName=' + portName + '&'); } /** * Deletes the specified data connection. * @param {number} connectionId */ Client.prototype.deleteDataConnection = function (connectionId) { return this.request('DELETE', '/api/v2/connections/dataconnections/' + connectionId + '?'); } /** * Create a power connection. Returns the newly created power connection. * @param {object} payload */ Client.prototype.createPowerConnection = function (payload) { return this.request('POST', '/api/v2/connections/powerconnections?', payload); } /** * Edit a power connection. Returns the newly edited power connection. * @param {number} connectionId * @param {object} payload */ Client.prototype.updatePowerConnection = function (connectionId, payload) { return this.request('PUT', '/api/v2/connections/powerconnections/' + connectionId + '?', payload); } /** * Get a power connection and associated details. Requires the ID of the connection you want to retrieve. Returns the requested power connection and associated details. * @param {number} connectionId */ Client.prototype.getPowerConnection = function (connectionId) { return this.request('GET', '/api/v2/connections/powerconnections/' + connectionId + '?'); } /** * Get power connection details based on the specified location, item name, and port name. Returns the JSON payload with the requested power connection details. * @param {string} location * @param {string} itemName * @param {string} portName */ Client.prototype.getPowerConnectionByNode = function (location, itemName, portName) { return this.request('GET', '/api/v2/connections/powerconnections?location=' + location + '&itemName=' + itemName + '&portName=' + portName + '&'); } /** * Deletes the specified power connection. Deletes the power connection. * @param {number} connectionId */ Client.prototype.deletePowerConnection = function (connectionId) { return this.request('DELETE', '/api/v2/connections/powerconnections/' + connectionId + '?'); } /** * Get power or data circuit details based on the specified circuit type location, item name, and port name. Returns the JSON payload with the requested power or data connection details. * @param {string} circuitType * @param {string} location * @param {string} itemName * @param {string} portName */ Client.prototype.getCircuit = function (circuitType, location, itemName, portName) { return this.request('GET', '/api/v2/dcimoperations/circuits/' + circuitType + '?location=' + location + '&itemName=' + itemName + '&portName=' + portName + '&'); } /** * Get links and nodes of entire power chain with customizable node details for a specific location. JSON entity containing data for the entire Power Chain for a given Location. The example below illustrates returning all fields by leaving the "selectedColumn" array empty. To limit the columns in the response, list the specific columns. * @param {number} locationId * @param {object} payload */ Client.prototype.retrievePowerChain = function (locationId, payload) { return this.request('POST', '/api/v2/powerChain/' + locationId + '?', payload); } /** * Get power sum for power ports with port ID list. * @param {object} payload */ Client.prototype.retrievePowerSumForPorts = function (payload) { return this.request('POST', '/api/v2/powerChain/powerSum/bulk?', payload); } /** * Get power sum for power ports using item ID list. * @param {object} payload */ Client.prototype.retrievePowerSumForItems = function (payload) { return this.request('POST', '/api/v2/items/powerSum/bulk?', payload); } /** * Update Actual Readings for Power Ports for an Item. * @param {number} itemId */ Client.prototype.getActualReadingsByItem = function (itemId) { return this.request('GET', '/api/v2/powerChain/items/actualReadings/' + itemId + '?'); } /** * Retrieve Actual Readings for Power Ports for multiple Items. * @param {object} payload */ Client.prototype.retrieveActualReadingsByItems = function (payload) { return this.request('POST', '/api/v2/powerChain/items/actualReadings/bulk?', payload); } /** * Update Actual Readings for Power Ports on one or more items. * @param {object} payload */ Client.prototype.retrieveActualReadingsByPorts = function (payload) { return this.request('POST', '/api/v2/powerChain/ports/actualReadings/bulk?', payload); } /** * Update Actual Readings By Port. * @param {number} portId * @param {object} payload */ Client.prototype.updateActualReadingsByPort = function (portId, payload) { return this.request('PUT', '/api/v2/powerChain/ports/actualReadings/' + portId + '?', payload); } /** * Get Actual Readings By Port. * @param {number} portId */ Client.prototype.getActualReadingsByPort = function (portId) { return this.request('GET', '/api/v2/powerChain/ports/actualReadings/' + portId + '?'); } /** * Get Ticket by Ticket ID. * @param {number} ticketId */ Client.prototype.getTicket = function (ticketId) { return this.request('GET', '/api/v2/tickets/' + ticketId + '?'); } /** * Create a Ticket. * @param {object} payload */ Client.prototype.createTicket = function (payload) { return this.request('POST', '/api/v2/tickets?', payload); } /** * Update a Ticket. * @param {number} ticketId * @param {object} payload */ Client.prototype.updateTicket = function (ticketId, payload) { return this.request('PUT', '/api/v2/tickets/' + ticketId + '?', payload); } /** * Delete Ticket by Ticket ID. * @param {number} ticketId * @param {boolean} proceedOnWarning */ Client.prototype.deleteTicket = function (ticketId, proceedOnWarning) { return this.request('DELETE', '/api/v2/tickets/' + ticketId + '?proceedOnWarning=' + proceedOnWarning + '&'); } /** * Search for Tickets using criteria JSON object. Search criteria can be any of the fields applicable to Tickets, including custom fields. Specify the fields to be included in the response. This API supports pagination. Returns a list of Tickets with the specified information. * @param {number} pageNumber * @param {number} pageSize * @param {object} payload */ Client.prototype.searchTickets = function (pageNumber, pageSize, payload) { return this.request('POST', '/api/v2/quicksearch/tickets?pageNumber=' + pageNumber + '&pageSize=' + pageSize + '&', payload); } /** * Returns a list of all Ticket fields. */ Client.prototype.getTicketFieldList = function () { return this.request('GET', '/api/v2/quicksearch/tickets/ticketListFields?'); } /** * Add/Update/Delete Tickets in Bulk. The body of the Request should contain the required fields required to perform the specified Method. * @param {object} payload */ Client.prototype.createTicketsBulk = function (payload) { return this.request('POST', '/api/v2/tickets/bulk?', payload); } /** * Assign Item to Ticket. The entity Ids provided in the Request should be the ID of the entity to be assigned to the Ticket. * @param {string} entityType * @param {object} payload */ Client.prototype.createTicketAssignment = function (entityType, payload) { return this.request('POST', '/api/v2/tickets/assignment/' + entityType + '/assign?', payload); } /** * Unassign Item from Ticket. This API will disassociate multiple Items or Circuits from a Ticket. The Ids provided in the Request should be the IDs of the assignment records. * @param {string} entityType * @param {object} payload */ Client.prototype.removeTicketAssignment = function (entityType, payload) { return this.request('POST', '/api/v2/tickets/assignment/' + entityType + '/unassign?', payload); } /** * Creates a custom field. Returns the newly created custom field. * @param {object} payload */ Client.prototype.createCustomField = function (payload) { return this.request('POST', '/api/v2/settings/lists/customFields?', payload); } /** * Update the definitions of the specified custom fields. Returns the updated custom field definitions. * @param {number} customFieldId * @param {object} payload */ Client.prototype.updateCustomField = function (customFieldId, payload) { return this.request('PUT', '/api/v2/settings/lists/customFields/' + customFieldId + '?', payload); } /** * Get a list of custom fields. Returns a list of all custom fields. * @param {string} orderPickListsBy */ Client.prototype.getCustomFields = function (orderPickListsBy) { return this.request('GET', '/api/v2/settings/lists/customFields?orderPickListsBy=' + orderPickListsBy + '&'); } /** * Get the custom field details for a given customFieldId. Passing a -1 value will return all the labels with null values. Returns a list of custom field details for the specified custom field. * @param {number} customFieldId * @param {string} orderPickListsBy */ Client.prototype.getCustomField = function (customFieldId, orderPickListsBy) { return this.request('GET', '/api/v2/settings/lists/customFields/' + customFieldId + '?orderPickListsBy=' + orderPickListsBy + '&'); } /** * Deletes the specified custom field and associated pick lists. * @param {number} customFieldId * @param {boolean} proceedOnWarning */ Client.prototype.deleteCustomField = function (customFieldId, proceedOnWarning) { return this.request('DELETE', '/api/v2/settings/lists/customFields/' + customFieldId + '?proceedOnWarning=' + proceedOnWarning + '&'); } /** * Returns the current Webhook configuration information. */ Client.prototype.getWebhook = function () { return this.request('GET', '/api/v2/notifications/config?'); } /** * Update the Webhook configuration information. * @param {object} payload */ Client.prototype.updateWebhook = function (payload) { return this.request('PUT', '/api/v2/notifications/config?', payload); } /** * Deletes the Webhook configuration. */ Client.prototype.deleteWebhook = function () { return this.request('DELETE', '/api/v2/notifications/config?'); } /** * Get Relationship details using the Relationship ID. * @param {number} id */ Client.prototype.getRelationship = function (id) { return this.request('GET', '/api/v2/relationship/' + id + '?'); } /** * Create a new entity link. Returns the newly created item JSON object. Note: Supported entity Types are "PROJECT", "TICKET", "ITEM". * @param {object} payload */ Client.prototype.createRelationship = function (payload) { return this.request('POST', '/api/v2/relationship?', payload); } /** * Search for Entity Links BY Entity Type and Entity ID. Entity Types are "PROJECT", "ITEM". Returns a Project JSON object. * @param {string} entityType * @param {number} entityId */ Client.prototype.getRelationshipByEntity = function (entityType, entityId) { return this.request('GET', '/api/v2/relationship/' + entityType + '/' + entityId + '?'); } /** * Search for Entity Links. Returns an array of Relationship links for the entity type. * @param {object} payload */ Client.prototype.searchRelationships = function (payload) { return this.request('POST', '/api/v2/relationship/search?', payload); } /** * Delete an Entity Link using the Relationship ID. * @param {number} id */ Client.prototype.deleteRelationship = function (id) { return this.request('DELETE', '/api/v2/relationship/' + id + '?'); } /** * Get floormap configuration for specific location. * @param {number} locationId */ Client.prototype.getFloormapConfig = function (locationId) { return this.request('GET', '/api/v2/visualization/floormaps/configuration/' + locationId + '?'); } /** * Get floormap configuration for all locations. */ Client.prototype.getFloormapConfigs = function () { return this.request('GET', '/api/v2/visualization/floormaps/configuration?'); } /** * Modify floormap configuration for specific location. * @param {number} locationId * @param {object} payload */ Client.prototype.updateFloormapConfig = function (locationId, payload) { return this.request('PUT', '/api/v2/visualization/floormaps/configuration/' + locationId + '?', payload); } /** * Modify floormap configurations for multiple locations. * @param {object} payload */ Client.prototype.createFloormapConfigsBulk = function (payload) { return this.request('POST', '/api/v2/visualization/floormaps/configuration/bulk?', payload); } /** * Add a new Project. JSON entity containing Project information that was passed in from the Request payload. * @param {object} payload */ Client.prototype.createProject = function (payload) { return this.request('POST', '/api/v2/dcimoperations/projects?', payload); } /** * Modify a Project. JSON entity containing Project information that was passed in from the Request payload. * @param {number} id * @param {object} payload */ Client.prototype.updateProject = function (id, payload) { return this.request('PUT', '/api/v2/dcimoperations/projects/' + id + '?', payload); } /** * Delete a Project using the Project ID. * @param {number} id */ Client.prototype.deleteProject = function (id) { return this.request('DELETE', '/api/v2/dcimoperations/projects/' + id + '?'); } /** * Get Project details using the Project ID. Returns a Project JSON object. * @param {number} id */ Client.prototype.getProject = function (id) { return this.request('GET', '/api/v2/dcimoperations/projects/' + id + '?'); } /** * Create Part Classes. Returns JSON entity containing data for the created Part Class. * @param {object} payload */ Client.prototype.createPartClass = function (payload) { return this.request('POST', '/api/v2/parts/classes?', payload); } /** * Update Part Classes. Returns JSON entity containing data for the updated Part Class. * @param {number} classId * @param {object} payload */ Client.prototype.updatePartClass = function (classId, payload) { return this.request('PUT', '/api/v2/parts/classes/' + classId + '?', payload); } /** * Delete Part Class by Class ID. * @param {number} classId */ Client.prototype.deletePartClass = function (classId) { return this.request('DELETE', '/api/v2/parts/classes/' + classId + '?'); } /** * Returns a list of Part Classes with basic information. */ Client.prototype.getPartClasses = function () { return this.request('GET', '/api/v2/parts/classes?'); } /** * Create, Update, Delete Part Classes in Bulk. Returns JSON entity containing a list of response codes. * @param {object} payload */ Client.prototype.createPartClassesBulk = function (payload) { return this.request('POST', '/api/v2/parts/classes/bulk?', payload); } /** * Create Part Model. Returns JSON entity containing data for the created Part Model. * @param {object} payload */ Client.prototype.createPartModel = function (payload) { return this.request('POST', '/api/v2/partModels?', payload); } /** * Update a Part Model. Returns JSON entity containing data for the Updated Part Model. * @param {number} modelId * @param {object} payload */ Client.prototype.updatePartModel = function (modelId, payload) { return this.request('PUT', '/api/v2/partModels/' + modelId + '?', payload); } /** * Delete Part Model by Model ID. * @param {number} modelId */ Client.prototype.deletePartModel = function (modelId) { return this.request('DELETE', '/api/v2/partModels/' + modelId + '?'); } /** * Get Model by Model ID. Returns JSON entity containing data for a single Model. * @param {number} modelId */ Client.prototype.getPartModel = function (modelId) { return this.request('GET', '/api/v2/partModels/' + modelId + '?'); } /** * Search for Part Models using criteria JSON object. Search criteria can be any of the fields applicable to Part Models, including custom fields. Specify the field to be included in the response. This API supports pagination. Returns a list of Part Models with the specified information. * @param {number} pageNumber * @param {number} pageSize * @param {object} payload */ Client.prototype.searchPartModels = function (pageNumber, pageSize, payload) { return this.request('POST', '/api/v2/quicksearch/parts/models?pageNumber=' + pageNumber + '&pageSize=' + pageSize + '&', payload); } /** * Delete a Part Model Image using the Part Model ID. * @param {number} modelId */ Client.prototype.deletePartModelImage = function (modelId) { return this.request('DELETE', '/api/v2/partModels/images/' + modelId + '?'); } /** * Create, Update, Delete Part Models in Bulk. Returns JSON entity containing a list of response codes. * @param {object} payload */ Client.prototype.createPartModelsBulk = function (payload) { return this.request('POST', '/api/v2/partModels/bulk?', payload); } /** * Returns a list of all Part Model fields. */ Client.prototype.getPartModelFieldList = function () { return this.request('GET', '/api/v2/quicksearch/parts/partModelListFiel