How to get the CI class name through REST API

David Casper
Tera Guru

We have an integration pulling CIs from the cmdb_ci table and need the class name rather than the actual table which is returned when you get the value for the cmdb_ci.sys_class_name field.

Curious how to pull the class name (not table name) through a REST call. 

getClassDisplayValue() method is used when scripting inside SNOW itself, but I can't seem to find out how to get that result through the API. 

Thanks!

 

1 ACCEPTED SOLUTION

Giles Lewis
Giga Guru

You can add "sysparm_display_value=all" to your URL. Here is an example

Script

#!/bin/bash
instance=********
username=********
password=********
sysid=a22be6f1dbfde7007c7e54f948961944
fieldnames=sys_id,name,manufacturer,sys_class_name
base="https://$instance.service-now.com/api/now/table/cmdb_ci/$sysid"
parms="sysparm_fields=$fieldnames&sysparm_display_value=all"
url="$base?$parms"
curl $url --request GET --user "$username:$password"

Output

{
    "result": {
        "sys_id": {
            "display_value": "a22be6f1dbfde7007c7e54f948961944",
            "value": "a22be6f1dbfde7007c7e54f948961944"
        },
        "name": {
            "display_value": "b24-rtr-2",
            "value": "b24-rtr-2"
        },
        "sys_class_name": {
            "display_value": "IP Router",
            "value": "cmdb_ci_ip_router"
        },
        "manufacturer": {
            "display_value": "Cisco",
            "link": "https://********.service-now.com/api/now/table/core_company/fc8318026fc8de002cc8186e6b3ee4ce",
            "value": "fc8318026fc8de002cc8186e6b3ee4ce"
        }
    }
}

View solution in original post

9 REPLIES 9

Patrick DeCarl1
ServiceNow Employee
ServiceNow Employee
Class and table name are the same. Are you asking for the label of class? You might need to do a second call to get table label or create your own scripted api

Yes, the lable, or table name. It's stored on the sys_choice table but would like to access it through the API similarly to the way you get to it internally. Not sure that is possible though. 

If there is not a simple solution I still would like to find out what the actual solution would be 

You will need to make two calls, a call tables to get their label or make a scripted api so you can call that runs the getClassDisplayValue() and return value you want.

Or add new custom field to ci tables to store their table label.