What is API for the Adding Relationships (api/now/cmdbrelation/)?

codycotulla
Tera Guru

Hi,

I am trying to test the Relationship editor, and I see that there is a Quick Start ATF test and it works. However the REST Post step that calls /api/now/cmdbrelation/add-rel doesn't take any parameters.

The test creates two records and then makes a call to the /api/now/cmdbrelation/add-rel, and the relationship is added to between the two records that were created, but it seems to happen by "magic".

A later step in the test makes a call to api/now/cmdbrelation/delete-rels, And that step does specify parameters.

My question is, what are the parameters for /api/now/cmdbrelation/add-rel and /api/now/cmdbrelation/add-rels

By the way, the quick start test I'm referring to is "CMDB REL EDITOR: Relationship Editor".

I appreciate any help!

Thanks,

Cody

1 ACCEPTED SOLUTION

codycotulla
Tera Guru

Well, I tracked down the body content for the POST messages.

The -- sys_id -- marker is where the sys_id of the Cis need to be.

 api/now/cmdbrelation/delete-rel

{
    "parentId": "-- sys_id --",
    "childId": "-- sys_id--",
    "relationTypeId": "1a9cb166f1571100a92eb60da2bce5c5",
    "type": "cmdb_ci",
    "isSuggestedRelationship": "true"
}

 api/now/cmdbrelation/delete-rels

{
    "item": [
        {
            "type": "Hosted on::Hosts",
            "type_id": "5f985e0ec0a8010e00a9714f2a172815",
            "child": "CMDB_ATF_RE_linux100",
            "child_id": "--sys_id--",
            "parent": "CMDB_ATF_RE_MySQL-16006",
            "parent_id": "--sys_id--",
            "sys_id": "",
            "relationshipType": "ci_upstream"
        },
        {
            "type": "Hosted on::Hosts",
            "type_id": "5f985e0ec0a8010e00a9714f2a172815",
            "child": "CMDB_ATF_RE_linux100",
            "child_id": "--sys_id--",
            "parent": "CMDB_ATF_RE_MySQL-16004",
            "parent_id": "--sys_id--",
            "sys_id": "",
            "relationshipType": "ci_upstream"
        }
    ],
    "type": "cmdb_ci",
    "isSuggestedRelationship": "true"
}

Hope this helps someone!

Thanks,

Cody

View solution in original post

8 REPLIES 8

sebastian_g_snc
ServiceNow Employee
ServiceNow Employee

Hi Cody,

the table that holds all CI relationships is cmdb_rel_ci .

In which quick start test suit did you find that test?

 

sebastian_g_snc
ServiceNow Employee
ServiceNow Employee

oh and btw: you could always user the normal table api to create CI relationships:

/api/now/table/cmdb_rel_ci

you can easily test that in the REST API explorer.

Sudhanshu Talw1
Tera Guru

All the relationships are stored in cmdb_rel_ci table.So it will be:

The best way i tell you just go to REST API explorer type the table name & you will get the end point.

If table name is unknown in any case just open a record & the URL is displaying it.

 /api/now/table/cmdb_rel_ci

Complete end point:

 https://<instance name>.service-now.com/api/now/table/cmdb_rel_ci

 

Thanks

Sudhanshu

 

emir
ServiceNow Employee
ServiceNow Employee

the POST contains this JSON:

{"parentId":"{{Step 6: Record Insert.Record}}","childId":"{{Step 5: Record Insert.Record}}","relationTypeId":"1a9cb166f1571100a92eb60da2bce5c5","type":"cmdb_ci","isSuggestedRelationship":"true"}