From 539c54d0c40152fe0a69520362ecfda16c5ade55 Mon Sep 17 00:00:00 2001 From: Amit Gujarathi Date: Tue, 17 Oct 2023 00:22:51 +0530 Subject: [PATCH 1/3] Create RetrieveCis.js Created Scripted Rest Resource for the API to Retrieve CIs --- Scripted REST Api/CMDB API/RetrieveCis.js | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 Scripted REST Api/CMDB API/RetrieveCis.js diff --git a/Scripted REST Api/CMDB API/RetrieveCis.js b/Scripted REST Api/CMDB API/RetrieveCis.js new file mode 100644 index 0000000000..d187bb0600 --- /dev/null +++ b/Scripted REST Api/CMDB API/RetrieveCis.js @@ -0,0 +1,6 @@ +(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) { + + // implement resource here + return new CmdbApi(request, response).getCis(); + +})(request, response); From 7d81afbeb26af46a6c211eca81b84bd74003e055 Mon Sep 17 00:00:00 2001 From: Amit Gujarathi Date: Tue, 17 Oct 2023 00:31:19 +0530 Subject: [PATCH 2/3] Update CmdbApi.js Added function getCis to retrieves Configuration Items (CIs) based on the specified CI type. --- Scripted REST Api/CMDB API/CmdbApi.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Scripted REST Api/CMDB API/CmdbApi.js b/Scripted REST Api/CMDB API/CmdbApi.js index 5e42bb4a10..3cf4c29680 100644 --- a/Scripted REST Api/CMDB API/CmdbApi.js +++ b/Scripted REST Api/CMDB API/CmdbApi.js @@ -299,6 +299,27 @@ createCiRelationship: function() { sysparm_limit: 100 }); }, + +/** + * Retrieves Configuration Items (CIs) based on the specified CI type. + * Mapped to GET /cis/{ci_type} + * @returns {GlideRecordStream} A stream of GlideRecord objects representing the CIs. + * @throws {BadRequestError} If an invalid CI type is provided. + */ + getCis: function() { + var self = this; + + var ciType = self.getPathParam('ci_type', ''); + + if (!self._isValidCiType(ciType)) { + return sn_ws_err.BadRequestError('Invalid CI Type provided:' + ciType); + } + + return self._getGrResultStream(ciType, null, { + sysparm_limit: 100 + }); + + }, /** * Determine the type of source ID. From eb1363365603f94c2bca7ad6fd02a7a304915e96 Mon Sep 17 00:00:00 2001 From: Amit Gujarathi Date: Tue, 17 Oct 2023 00:35:13 +0530 Subject: [PATCH 3/3] Update readme.md This file contains a ServiceNow script that implements a function for retrieving Configuration Items (CIs) based on a specified CI type. --- Scripted REST Api/CMDB API/readme.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Scripted REST Api/CMDB API/readme.md b/Scripted REST Api/CMDB API/readme.md index 1884e5ffca..4b1e08cd80 100644 --- a/Scripted REST Api/CMDB API/readme.md +++ b/Scripted REST Api/CMDB API/readme.md @@ -8,6 +8,7 @@ Table of Contents 4. Delete CI Relationship 5. Retrieve CI Group 6. Retrieve CI Relationship types +7. Retrieve CIs 1. Create CIs This API is designed to create Configuration Items (CIs). @@ -99,3 +100,17 @@ Table of Contents Response: Status Code: 200 OK Response Body: Details of CI Relationship types + + 7. Retrieve CIs + Scripted REST API Resource contains a ServiceNow script that implements a function for retrieving Configuration Items (CIs) based on a specified CI type. + Request Details: + Type: HTTP + Method: GET + URI: https://.service-now.com/api/cis/{ci_type} + Headers: + Accept: application/json + Content-Type: application/json + Request Body: NA + Response: + Status Code: 200 OK + Response Body: JSON Details of CIs based on the given type