API call to create CI fails because of missing dependency

Geert Huylebro1
ServiceNow Employee
ServiceNow Employee

Hi,

when trying to create a CI (of class cmdb_ci_apache_web_server), the API call fails with the "error": "MISSING_DEPENDENCY".

The related message is "In payload no relations defined for dependent class [cmdb_ci_apache_web_server] that matches any containment/hosting rules: [cmdb_ci_appl >> Runs on >> cmdb_ci_hardware]."

 

Following is the body of the call: 

{
"attributes": {
"asset_tag": "tag_lx_web_app40",
"company": "ServiceNow",
"environment": "dev",
"name": "Apache Server @ lx_web_app40",
"type": "Apache",
"tcp_port": "80"
},
"source": "ServiceNow",
"inbound_relations":[
{
"type": "60bc4e22c0a8010e01f074cbe6bd73c3",
"target": "2f5a7e3c47cce15050235e17e26d43e0",
"cmdb_class_name": "cmdb_ci_linux_server"
}
]
}
 
in which type is the sys_id of the RunsOn::Runs relationship type.
The 'target' is the sys_id of the existing Linux server CI.
Anyone has any idea?
 
kr
Geert
2 ACCEPTED SOLUTIONS

In the meantime I have found another post, here on community that helped me in the right direction, and I have managed to do the CI creation using payload:

{
	"attributes": {
		"asset_tag": "tag_lx_web_app40",
		"company": "ServiceNow",
		"config_file": "/etc/httpd/httpd.conf",
		"environment": "dev",
		"name": "Apache Server @ lx_web_app40",
		"type": "Apache",
		"tcp_port": "80",
		"version": "2.4.54"
	},
	"depends_on": {
		"outbound_relations": {
			"type": "60bc4e22c0a8010e01f074cbe6bd73c3",
			"target": "539747cac0a801640163e60735fbbf6e"
		}

	},
	"source": "ServiceNow"
}

It seems there is a total disconnect between what exists and what is described in the documentation 😞

It seems in case of depending CIs one has to add an additional property to the payload: depends_on. And it has to contain the relationship that indicates the parent CI. As you can see you still have to add outbound relation, not an inbound one. Oh, for sure you will need to update "target" of "outbound_relations" to be that of the Linux (or whatever) server you have in your CMDB.

Here's the Linux server before calling the API:

2023-01-03-1.png

and here it is after calling the API:

2023-01-03-2.png

 

View solution in original post

Also, note that property "attributes" must contain the field names (config_file) not the field labels (Configuration file)!

View solution in original post

16 REPLIES 16

-O-
Kilo Patron
Kilo Patron

That does not look like an IRE payload. I'm assuming it's IRE based on the error message. IRE payloads as far as I know are supposed to be objects that contain arrays "items" and "relations". E.g. the code

var payload = {
	'items': [
		{
			'className': 'cmdb_ci_apache_web_server',
			'internal_id': 'a0',
			'values': {
				'asset_tag': 'tag_lx_web_app40',
				'company': 'ServiceNow',
				'config_file': '/etc/httpd/httpd.conf',
				'environment': 'dev',
				'name': 'Apache Server @ lx_web_app40',
				'type': 'Apache',
				'tcp_port': '80',
				'version': '2.4.54',
			},
		},
		{
			'className': 'cmdb_ci_linux_server',
			'internal_id': 'a1',
			'values': {
				'name': 'Abc-123',
			},
		},
	],
	'relations': [
		{
			'parent_id': 'a0',
			'child_id': 'a1',
			'type': 'Runs on::Runs',
		},
	],
};

var output = SNC.IdentificationEngineScriptableApi.createOrUpdateCIEnhanced('ServiceNow', JSON.stringify(payload), {});

gs.print(output);

does create (and subsequently update) a linux and a web server.

Posting more details would be helpful.

Geert Huylebro1
ServiceNow Employee
ServiceNow Employee

Hi,

 

indeed the payload I provided is what I have in Postman

I'd like to understand what is missing in that payload to create the web server and the relation to the linux server

kr

Geert

 

 

Mentioning Postman is a clear indication that my answer has nothing to do with your problem. You are probably calling some REST endpoint. If so, which one? If not, what are you calling using Postman?

If you are calling one of the Identification and Reconciliation API end-points, just did a test, pasted the payload above ({"items":[{"className":"cmdb_ci_apache_web_server","internal_id":"a0","values":{"asset_tag":"tag_lx_web_app40","company":"ServiceNow","config_file":"/etc/httpd/httpd.conf","environment":"dev","name":"Apache Server @ lx_web_app40","type":"Apache","tcp_port":"80","version":"2.4.54"}},{"className":"cmdb_ci_linux_server","internal_id":"a1","values":{"name":"Abc-124"}}],"relations":[{"parent_id":"a0","child_id":"a1","type":"Runs on::Runs"}]}) as Raw request body for end-point

POST https://devxxxxx.service-now.com/api/now/identifyreconcile/enhanced

have set parameter sysparm_data_source to ServiceNow and it did the same as the code: 1st create than later update the created CIs.