How to create a API for CMDB
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-11-2025 03:25 AM
How to create an API for the CMDB to receive data from an external application and properly create or update records in the appropriate CMDB tables.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-11-2025 03:38 AM
data in CMDB can be populated from various sources such as Discovery, Data load
what's your scenario?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-11-2025 03:39 AM
Practically, the CMDB is updated via Discovery, which is a good approach. Since you mentioned having an external system, please check if there is an API available for the CMDB.
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-11-2025 03:39 AM
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-11-2025 11:28 PM
Hello @komal shetty
Generally we will use any of below methods:
1. Discovery
2. Integration with external systems
3. Manual upload (Import Sets)
I've implemented similar solution for my customer, please find the below solution:
1. Identify the Target CMDB Table(s)
For example:
Computers/Servers: cmdb_ci_computer
Network Devices: cmdb_ci_network
Generic CI: cmdb_ci
2. Create a Custom Scripted REST API
System Web Services > Scripted REST APIs
Click New
Fill in:
Name: CMDB Integration API
API ID: cmdb_integration
Namespace: leave as default or customize
Check "Active"
You now have an API base path like:
https://instance.service-now.com/api/x_namespace/cmdb_integration
3. Create a Resource (Endpoint)
Inside your new API, go to the Resources tab
Click New
Set:
HTTP Method: POST (for create/update)
Relative Path: e.g., ci
Script: This will define your logic to create or update CMDB records
4. Add Logic to the Script
Here’s a sample script for POST /ci to create or update a CI based on a unique identifier (like name or serial_number):
CODE:
(function process(request, response) {
var payload = request.body.data;
if (!payload || !payload.name) {
response.setStatus(400);
response.setBody({error: 'Missing required field: name'});
return;
}
var ci = new GlideRecord('cmdb_ci_computer');
ci.addQuery('name', payload.name);
ci.query();
if (ci.next()) {
// Update existing record
gs.info("Updating existing CI: " + ci.name);
} else {
// Create new CI
ci.initialize();
gs.info("Creating new CI");
}
// Set common fields
ci.name = payload.name;
ci.ip_address = payload.ip_address || '';
ci.serial_number = payload.serial_number || '';
ci.manufacturer = payload.manufacturer || '';
ci.model_id = payload.model_id || '';
var sysId = ci.insert() || ci.update();
response.setStatus(200);
response.setBody({
message: "CI processed successfully",
sys_id: ci.getUniqueValue()
});
})(request, response);
5. Secure the API (Important!)
Create an API Role
Create a new role (e.g., x_cmdb.api_user)
Assign this role to users or OAuth profiles that should access the API
Add the role to the API
In the Scripted REST API record, add the role under Accessible from Roles
6. Authenticate External Systems
Recommend using OAuth 2.0
Configure in System OAuth > Application Registry
Generate a Client ID/Secret for external system
External system will:
Request a token from /oauth_token.do
Use that token to call your CMDB API