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

emir
ServiceNow Employee
ServiceNow Employee

the odd thing is, I cannot see the content if I am using global scope. I would love it if you could open a ticket on this ..

codycotulla
Tera Guru

Hi Emir,

I have opened up a Hi ticket for the disappearing field data. I found that the problem is with the datapills. 

Here's what's happening. 

If the test has multiple steps of the same type, say multiple Insert Record steps, then only one of those steps can be used as the content of a string field, like the Body of the REST message. Typically it's the first step of the type created. 

If you put the data pill from one of the other steps into the string field then when you save the record the contents of the String field are blanked out, which is the behavior we're seeing with these REST messages.

Hope it helps to know what's causing the problem even if we don't know why.

Thanks again for finding the "hidden" contents of the Body field. It allowed me to move forward.

Regards,

Cody

emir
ServiceNow Employee
ServiceNow Employee

Thank you for making the product better! The community appreciates you Cody!

 

Emir

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