Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Rest API to fetch all table's columns for a given table

Jorge Martinez1
Kilo Contributor

Hello.

 

Do you know any way we can retrieve tables and columns metadata through the REST APIs? What I need is a list of columns for a given table.

The below query for the Incident table only returns the fields that are below to Incident, but Incident has a Task as a parent and I need to include those columns two also.

{instance}/api/now/v1/table/sys_dictionary?sysparm_query=name=incident

 

 

Thank you,

 

5 REPLIES 5

philippesab
Tera Contributor

try:

https://{instance}/api/now/table/sys_dictionary?sysparm_query=name%3Dincident&sysparm_exclude_reference_link=true&sysparm_fields=element%2Cinternal_type%2Ccolumn_label
 
where:
  • name is the table name (name=incident)
  • sysparm_fields are actual column in the sys_dictionary table where:
    • element in the name of the columns
    • element_label is the display name of the columns
    • internal_type is the type of the column (integer, string..)
  • sysparm_exclude_reference_link=true will only give you the value of any linked object (in this case internal_type)
 
this should give you the following results:

 

{
  "result": [
    {
      "column_label": "On hold reason",
      "internal_type": "integer",
      "element": "hold_reason"
    },
    {
      "column_label": "Category",
      "internal_type": "string",
      "element": "category"
    },
    {
      "column_label": "Origin",
      "internal_type": "document_id",
      "element": "origin_id"
    },
    {
      "column_label": "Notify",
      "internal_type": "integer",
      "element": "notify"
    },
    {
      "column_label": "Last reopened by",
      "internal_type": "reference",
      "element": "reopened_by"
    },
    {
      "column_label": "Probable cause",
      "internal_type": "string",
      "element": "cause"
    },
    {
      "column_label": "Caused by Change",
      "internal_type": "reference",
      "element": "caused_by"
    },
    {
      "column_label": "Business resolve time",
      "internal_type": "integer",
      "element": "business_stc"
    },
    {
      "column_label": "Severity",
      "internal_type": "integer",
      "element": "severity"
    },
    {
      "column_label": "Reopen count",
      "internal_type": "integer",
      "element": "reopen_count"
    }
  ]
}