<service domain|custom domain>/app/<portal>/api/v3/cmdb/{ci_type_api_name}/{ci_id}/ci_relationships
CI 关系
定义一个 CI 如何连接到另一个 CI。CI 与 CI 之间的关系可以是自定义的或建议的。
获取 CI 关系列表
此操作有助于获取 CI 的所有关系。
URL
<service domain|custom domain>/app/<portal>/api/v3/cmdb/{ci_type_api_name}/{ci_id}/ci_relationships
$ curl -G <service domain|custom domain>/app/<portal>/api/v3/cmdb/{ci_type_api_name}/{ci_id}/ci_relationships\
-X GET\
-H "Accept: application/vnd.manageengine.sdp.v3+json"\
-H "Authorization: Zoho-oauthtoken 1000.7xxx98976ab0xxxxxx19901e7551be57.bxxxx921ed64c04f79622bebcfxxxxxx"\
-H "Content-Type: application/x-www-form-urlencoded"
// Deluge Sample script
url = "<service domain|custom domain>/app/<portal>/api/v3/cmdb/{ci_type_api_name}/{ci_id}/ci_relationships";
headers = {"Accept":"application/vnd.manageengine.sdp.v3+json",
"Content-Type": "application/x-www-form-urlencoded",
"Authorization": "Zoho-oauthtoken 1000.7xxx98976ab0xxxxxx19901e7551be57.bxxxx921ed64c04f79622bebcfxxxxxx"};
response = invokeurl
[
url: url
type: GET
headers: headers
];
info response;
#Powershell version - 5.1
$url = "<service domain|custom domain>/app/<portal>/api/v3/cmdb/{ci_type_api_name}/{ci_id}/ci_relationships"
$headers = @{ "Accept" = "application/vnd.manageengine.sdp.v3+json"
"Authorization" = "Zoho-oauthtoken 1000.7xxx98976ab0xxxxxx19901e7551be57.bxxxx921ed64c04f79622bebcfxxxxxx"
"Content-Type" = "application/x-www-form-urlencoded"}
$response = Invoke-RestMethod -Uri $url -Method get -Headers $headers
$response
#Python version - 3.8
#This script requires requests module installed in python.
from urllib.error import HTTPError
from urllib.parse import urlencode
from urllib.request import urlopen,Request
url = "<service domain|custom domain>/app/<portal>/api/v3/cmdb/{ci_type_api_name}/{ci_id}/ci_relationships"
headers ={"Accept": "application/vnd.manageengine.sdp.v3+json",
"Authorization" : "Zoho-oauthtoken 1000.7xxx98976ab0xxxxxx19901e7551be57.bxxxx921ed64c04f79622bebcfxxxxxx",
"Content-Type" : "application/x-www-form-urlencoded"}
httprequest = Request(url, headers=headers)
try:
with urlopen(httprequest) as response:
print(response.read().decode())
except HTTPError as e:
print(e.read().decode())
{
"response_status": [
{
"status_code": 2000,
"status": "success"
}
],
"list_info": {
"has_more_rows": false,
"row_count": 1
},
"ci_relationships": [
{
"related_ci": {
"ci_type": {
"api_plural_name": "ci_computer",
"name": "ci_computer",
"display_name_plural": "Computer",
"id": "100000000000030038",
"display_name": "Computer",
"icon_name": "exchange_server"
},
"name": "New Sample CI",
"id": "100000000000033079",
"relationship_count": 1
},
"is_inverse": false,
"citype_relationship": null,
"relationship_type": {
"name": "Connected to",
"description": "Relationship between items that is Connected",
"id": "100000000000030604",
"inverse_name": "Connected to"
},
"id": "100000000000033123",
"related_citype": {
"api_plural_name": "ci_computer",
"name": "ci_computer",
"display_name_plural": "Computer",
"id": "100000000000030038",
"display_name": "Computer",
"icon_name": "exchange_server"
}
}
]
}
添加 CI 之间的自定义关系
此操作允许向 CI 添加自定义关系
URL
$ curl <service domain|custom domain>/app/<portal>/api/v3/cmdb/{ci_type_api_name}/{ci_id}/ci_relationships\
-X POST\
-H "Accept: application/vnd.manageengine.sdp.v3+json"\
-H "Authorization: Zoho-oauthtoken 1000.7xxx98976ab0xxxxxx19901e7551be57.bxxxx921ed64c04f79622bebcfxxxxxx"\
-H "Content-Type: application/x-www-form-urlencoded"\
-d input_data='{
"ci_relationship": {
"relationship_type": {
"id": "100000000000030604"
},
"related_ci": {
"id": "100000000000032706"
},
"is_inverse": "false",
"related_citype": {
"id": "100000000000030038"
}
}
}'
// Deluge Sample script
url = "<service domain|custom domain>/app/<portal>/api/v3/cmdb/{ci_type_api_name}/{ci_id}/ci_relationships";
headers = {"Accept":"application/vnd.manageengine.sdp.v3+json",
"Content-Type": "application/x-www-form-urlencoded",
"Authorization": "Zoho-oauthtoken 1000.7xxx98976ab0xxxxxx19901e7551be57.bxxxx921ed64c04f79622bebcfxxxxxx"};
input_data = {
"ci_relationship": {
"relationship_type": {
"id": "100000000000030604"
},
"related_ci": {
"id": "100000000000032706"
},
"is_inverse": "false",
"related_citype": {
"id": "100000000000030038"
}
}
};
params = {"input_data": input_data};
response = invokeurl
[
url: url
type: POST
parameters: params
headers: headers
];
info response;
#Powershell version - 5.1
$url = "<service domain|custom domain>/app/<portal>/api/v3/cmdb/{ci_type_api_name}/{ci_id}/ci_relationships"
$headers = @{"Accept": "application/vnd.manageengine.sdp.v3+json",
"Authorization" : "Zoho-oauthtoken 1000.7xxx98976ab0xxxxxx19901e7551be57.bxxxx921ed64c04f79622bebcfxxxxxx",
"Content-Type" : "application/x-www-form-urlencoded"}
$input_data = @'
{
"ci_relationship": {
"relationship_type": {
"id": "100000000000030604"
},
"related_ci": {
"id": "100000000000032706"
},
"is_inverse": "false",
"related_citype": {
"id": "100000000000030038"
}
}
}
'@
$data = @{ 'input_data' = $input_data}
$response = Invoke-RestMethod -Uri $url -Method post -Body $data -Headers $headers
$response
#Python version - 3.10
from urllib.error import HTTPError
from urllib.parse import urlencode
from urllib.request import urlopen,Request
url = "<service domain|custom domain>/app/<portal>/api/v3/cmdb/{ci_type_api_name}/{ci_id}/ci_relationships"
headers ={"Accept": "application/vnd.manageengine.sdp.v3+json",
"Authorization" : "Zoho-oauthtoken 1000.7xxx98976ab0xxxxxx19901e7551be57.bxxxx921ed64c04f79622bebcfxxxxxx",
"Content-Type" : "application/x-www-form-urlencoded"}
input_data = '''{
"ci_relationship": {
"relationship_type": {
"id": "100000000000030604"
},
"related_ci": {
"id": "100000000000032706"
},
"is_inverse": "false",
"related_citype": {
"id": "100000000000030038"
}
}
}'''
data = urlencode({"input_data":input_data}).encode()
httprequest = Request(url, headers=headers,data=data, method="POST")
try:
with urlopen(httprequest) as response:
print(response.read().decode())
except HTTPError as e:
print(e.read().decode())
{
"ci_relationship": {
"comments": null,
"related_ci": {
"ci_type": {
"id": "100000000000030038"
},
"name": "New Sample CI",
"id": "100000000000032706"
},
"is_inverse": false,
"citype_relationship": null,
"relationship_type": {
"name": "Connected to",
"description": "Relationship between items that is Connected",
"id": "100000000000030604",
"inverse_name": "Connected to"
},
"id": "100000000000032712",
"related_citype": {
"api_plural_name": "ci_computer",
"name": "ci_computer",
"display_name_plural": "Computer",
"id": "100000000000030038",
"display_name": "Computer",
"icon_name": "exchange_server"
}
},
"response_status": {
"status_code": 2000,
"status": "success"
}
}
添加 CI 之间的建议关系
此操作帮助您添加两个配置项之间的建议关系。必填字段为 citype_relationship,related_ci
URL
<service domain|custom domain>/app/<portal>/api/v3/cmdb/{ci_type_api_name}/{ci_id}/ci_relationships
$ curl <service domain|custom domain>/app/<portal>/api/v3/cmdb/{ci_type_api_name}/{ci_id}/ci_relationships\
-X POST\
-H "Accept: application/vnd.manageengine.sdp.v3+json"\
-H "Authorization: Zoho-oauthtoken 1000.7xxx98976ab0xxxxxx19901e7551be57.bxxxx921ed64c04f79622bebcfxxxxxx"\
-H "Content-Type: application/x-www-form-urlencoded"\
-d input_data='{
"ci_relationship":{
"related_ci": {
"id": "100000000000040001"
},
"citype_relationship": {
"id": "100000000000041007"
}
}
}'
// Deluge Sample script
url = "<service domain|custom domain>/app/<portal>/api/v3/cmdb/{ci_type_api_name}/{ci_id}/ci_relationships";
headers = {"Accept":"application/vnd.manageengine.sdp.v3+json",
"Content-Type": "application/x-www-form-urlencoded",
"Authorization": "Zoho-oauthtoken 1000.7xxx98976ab0xxxxxx19901e7551be57.bxxxx921ed64c04f79622bebcfxxxxxx"};
input_data = {
"ci_relationship":{
"related_ci": {
"id": "100000000000040001"
},
"citype_relationship": {
"id": "100000000000041007"
}
}
};
params = {"input_data": input_data};
response = invokeurl
[
url: url
type: POST
parameters: params
headers: headers
];
info response;
#Powershell version - 5.1
$url = "<service domain|custom domain>/app/<portal>/api/v3/cmdb/{ci_type_api_name}/{ci_id}/ci_relationships"
$headers = @{"Accept": "application/vnd.manageengine.sdp.v3+json",
"Authorization" : "Zoho-oauthtoken 1000.7xxx98976ab0xxxxxx19901e7551be57.bxxxx921ed64c04f79622bebcfxxxxxx",
"Content-Type" : "application/x-www-form-urlencoded"}
$input_data = @'
{
"ci_relationship":{
"related_ci": {
"id": "100000000000040001"
},
"citype_relationship": {
"id": "100000000000041007"
}
}
}
'@
$data = @{ 'input_data' = $input_data}
$response = Invoke-RestMethod -Uri $url -Method post -Body $data -Headers $headers
$response
#Python version - 3.10
from urllib.error import HTTPError
from urllib.parse import urlencode
from urllib.request import urlopen,Request
url = "<service domain|custom domain>/app/<portal>/api/v3/cmdb/{ci_type_api_name}/{ci_id}/ci_relationships"
headers ={"Accept": "application/vnd.manageengine.sdp.v3+json",
"Authorization" : "Zoho-oauthtoken 1000.7xxx98976ab0xxxxxx19901e7551be57.bxxxx921ed64c04f79622bebcfxxxxxx",
"Content-Type" : "application/x-www-form-urlencoded"}
input_data = '''{
"ci_relationship":{
"related_ci": {
"id": "100000000000040001"
},
"citype_relationship": {
"id": "100000000000041007"
}
}
}'''
data = urlencode({"input_data":input_data}).encode()
httprequest = Request(url, headers=headers,data=data, method="POST")
try:
with urlopen(httprequest) as response:
print(response.read().decode())
except HTTPError as e:
print(e.read().decode())
{
"ci_relationship":{
"created_time":{
"display_value":"Aug 13, 2021 04:13 PM",
"value":"1628851406903"
},
"comments":null,
"related_ci":{
"ci_type":{
"id":"100000000000029962"
},
"name":"Application",
"id":"100000000000040001"
},
"is_inverse":true,
"created_by":{
"email_id": "lincoln@zmail.com",
"is_technician": true,
"sms_mail": "linc123@xys_sms.co",
"contact_info_id": "100000000000032677",
"mobile": "9876543210",
"last_name": "",
"user_scope": "0",
"phone": "",
"name": "Lincoln",
"id": "100000000000032679",
"photo_url": "test-photo-url",
"is_vip_user": false,
"department": null,
"first_name": "Lincoln",
"job_title": ""
},
"citype_relationship":{
"is_inverse":null,
"name":"ci_application_100000000000030540_ci_computer",
"id":"100000000000041007",
"cardinality":"many_to_many"
},
"last_updated_by":null,
"last_updated_time":null,
"relationship_type":{
"name":"Depends on",
"description":"Relationship between items that Depends On and Used By",
"id":"100000000000030540",
"inverse_name":"Used by"
},
"id":"100000000000041015",
"related_citype":{
"api_plural_name":"ci_application",
"name":"ci_application",
"display_name_plural":"Application",
"id":"100000000000029962",
"display_name":"Application",
"icon_name":"application"
}
},
"response_status":{
"status_code":2000,
"status":"success"
}
}
删除 CI 关系
此操作允许您删除自定义关系和建议关系
URL
<service domain|custom domain>/app/<portal>//api/v3/cmdb/{ci_type_api_name}/{ci_id}/ci_relationships/<ci_relationship_id>
$ curl <service domain|custom domain>/app/<portal>//api/v3/cmdb/{ci_type_api_name}/{ci_id}/ci_relationships/<ci_relationship_id>\
-X DELETE\
-H "Accept: application/vnd.manageengine.sdp.v3+json"\
-H "Authorization: Zoho-oauthtoken 1000.7xxx98976ab0xxxxxx19901e7551be57.bxxxx921ed64c04f79622bebcfxxxxxx"\
-H "Content-Type: application/x-www-form-urlencoded"
// Deluge Sample script
url = "<service domain|custom domain>/app/<portal>//api/v3/cmdb/{ci_type_api_name}/{ci_id}/ci_relationships/<ci_relationship_id>";
headers = {"Accept":"application/vnd.manageengine.sdp.v3+json",
"Content-Type": "application/x-www-form-urlencoded",
"Authorization": "Zoho-oauthtoken 1000.7xxx98976ab0xxxxxx19901e7551be57.bxxxx921ed64c04f79622bebcfxxxxxx"};
response = invokeurl
[
url: url
type: DELETE
headers: headers
];
info response;
#Powershell version - 5.1
$url = "<service domain|custom domain>/app/<portal>//api/v3/cmdb/{ci_type_api_name}/{ci_id}/ci_relationships/<ci_relationship_id>"
$headers = @{ "Accept" = "application/vnd.manageengine.sdp.v3+json"
"Authorization" = "Zoho-oauthtoken 1000.7xxx98976ab0xxxxxx19901e7551be57.bxxxx921ed64c04f79622bebcfxxxxxx"
"Content-Type" = "application/x-www-form-urlencoded"}
$response = Invoke-RestMethod -Uri $url -Method delete -Headers $headers
$response
#Python version - 3.10
from urllib.error import HTTPError
from urllib.request import urlopen,Request
url = "<service domain|custom domain>/app/<portal>//api/v3/cmdb/{ci_type_api_name}/{ci_id}/ci_relationships/<ci_relationship_id>"
headers ={"Accept": "application/vnd.manageengine.sdp.v3+json",
"Authorization" : "Zoho-oauthtoken 1000.7xxx98976ab0xxxxxx19901e7551be57.bxxxx921ed64c04f79622bebcfxxxxxx",
"Content-Type" : "application/x-www-form-urlencoded"}
httprequest = Request(url, headers=headers,method="DELETE")
try:
with urlopen(httprequest) as response:
print(response.read().decode())
except HTTPError as e:
print(e.read().decode())
{
"response_status": {
"status_code": 2000,
"status": "success"
}
}
批量删除 CI 关系
此操作允许您同时删除一个或多个自定义关系和建议关系。关系 ID 可以用逗号分隔的格式给出。
URL
<service domain|custom domain>/app/<portal>//api/v3/cmdb/{ci_type_api_name}/{ci_id}/ci_relationships?ids={ci_relationship_ids}
$ curl <service domain|custom domain>/app/<portal>//api/v3/cmdb/{ci_type_api_name}/{ci_id}/ci_relationships?ids={ci_relationship_ids}\
-X DELETE\
-H "Accept: application/vnd.manageengine.sdp.v3+json"\
-H "Authorization: Zoho-oauthtoken 1000.7xxx98976ab0xxxxxx19901e7551be57.bxxxx921ed64c04f79622bebcfxxxxxx"\
-H "Content-Type: application/x-www-form-urlencoded"
// Deluge Sample script
url = "<service domain|custom domain>/app/<portal>//api/v3/cmdb/{ci_type_api_name}/{ci_id}/ci_relationships?ids={ci_relationship_ids}";
headers = {"Accept":"application/vnd.manageengine.sdp.v3+json",
"Content-Type": "application/x-www-form-urlencoded",
"Authorization": "Zoho-oauthtoken 1000.7xxx98976ab0xxxxxx19901e7551be57.bxxxx921ed64c04f79622bebcfxxxxxx"};
response = invokeurl
[
url: url
type: DELETE
headers: headers
];
info response;
#Powershell version - 5.1
$url = "<service domain|custom domain>/app/<portal>//api/v3/cmdb/{ci_type_api_name}/{ci_id}/ci_relationships?ids={ci_relationship_ids}"
$headers = @{ "Accept" = "application/vnd.manageengine.sdp.v3+json"
"Authorization" = "Zoho-oauthtoken 1000.7xxx98976ab0xxxxxx19901e7551be57.bxxxx921ed64c04f79622bebcfxxxxxx"
"Content-Type" = "application/x-www-form-urlencoded"}
$response = Invoke-RestMethod -Uri $url -Method delete -Headers $headers
$response
#Python version - 3.10
from urllib.error import HTTPError
from urllib.request import urlopen,Request
url = "<service domain|custom domain>/app/<portal>//api/v3/cmdb/{ci_type_api_name}/{ci_id}/ci_relationships?ids={ci_relationship_ids}"
headers ={"Accept": "application/vnd.manageengine.sdp.v3+json",
"Authorization" : "Zoho-oauthtoken 1000.7xxx98976ab0xxxxxx19901e7551be57.bxxxx921ed64c04f79622bebcfxxxxxx",
"Content-Type" : "application/x-www-form-urlencoded"}
httprequest = Request(url, headers=headers,method="DELETE")
try:
with urlopen(httprequest) as response:
print(response.read().decode())
except HTTPError as e:
print(e.read().decode())
{
"response_status": {
"status_code": 2000,
"status": "success"
}
}