0

I an fetching CI dependency of Change request by rest api but i have to use multiple API to fetch CI dependency.

Can I use one Api to fetch CI dependency?

I am using this right now. /api/now/table/change_request?sysparm_query=number={CrNumber}

get sys_id from that

/api/now/table/<task_table>?sysparm_query=task%3D{cr_sys_id}

and then

/api/now/table/<cmd_ci table>?sysparm_query=sys_id%7d<ci_id>

And we get details.

Is there is more optimized way?

Himanshu sharma
  • 7,487
  • 4
  • 42
  • 75

1 Answers1

0

There are multiple ways of solving this:

  1. You can create your own Scripted REST API
  2. You can dot walk in the NOW table API

1 - Create a scripted rest API

You can script your own data retrieval using a GlideRecord to get the desired data by dot walking, based on just the change request number.

2 - Dot walk in the API

Request something as follows:
/api/now/table/change_request?sysparm_query=number%3<YOUR_NUMBER>&sysparm_fields=cmdb_ci.type%2Ccmdb_ci.name%2C%20cmdb_ci.version&sysparm_limit=1

In the sysparm_fields query param, you can pass dot walked fields to retrieve the desired data. In the example here I use the fields: "cmdb_ci.type,cmdb_ci.name,cmdb_ci.version"

Would result in something like:

{
  "result": [
    {
      "cmdb_ci.type": "Software or something type",
      "cmdb_ci.name": "Named thing",
      "cmdb_ci.version": "2.1"
    }
  ]
}
Dries Meerman
  • 96
  • 1
  • 6