> ## Documentation Index
> Fetch the complete documentation index at: https://docs.coreflux.org/llms.txt
> Use this file to discover all available pages before exploring further.

# ServiceNow

> Client-mode REST API connector for a curated ServiceNow Table API + Event Management slice: incidents from alarms, EM inbound events, CMDB CI patch, catalog tasks

Technical Preview

## Overview

A client-mode connector for a **curated ITSM / OT** slice of the [ServiceNow Table API](https://www.servicenow.com/docs/r/api-reference/rest-apis/c_TableAPI.html) and Event Management Connectors under `https://YOUR_INSTANCE.service-now.com`:

| Catalog connector event | Entity / path | Notes |
| - | - | - |
| (discovery / smoke) | `GET /api/now/table/incident` | List incidents (`sysparm_limit` in template) |
| POST table/incident from alarm | `POST /api/now/table/incident` | Create incident (flat JSON fields) |
| POST em/inbound\_event (Event Management) | `POST /api/sn_em_connector/em/inbound_event?source=` | **Verified EM Connectors path** — not `/api/now/em/inbound_event` |
| PATCH table/cmdb\_ci/\{sys\_id} | `PATCH /api/now/table/cmdb_ci/{sys_id}` | Generic CI table; fork for specific CI classes if needed |
| GET table/sc\_task?sysparm\_query= | `GET /api/now/table/sc_task?sysparm_query=` | Catalog / fulfillment tasks |

`BASE_ADDRESS` is `https://{instance}.service-now.com` (no trailing slash; endpoints already include `/api/...`). Topics use `itsm/servicenow/<object>/<verb>`.

> [!NOTE]
>
> Catalog wording places `em/inbound_event` under `/api/now/`. Public Event Management Connectors documentation uses `/api/sn_em_connector/em/inbound_event?source={sourceName}` (for example `genericJson`). Configure a push connector / event rule on the instance before posting events.

> [!NOTE]
>
> Prefer Hub secrets for tokens and passwords. This template has not been verified against a live ServiceNow instance. Status remains blocked until an authenticated live smoke succeeds.

## Basic Syntax

```lot wrap theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
# Coreflux REST_API template — ServiceNow (Table API + EM curated slice)
# Auth: Bearer {value.json.access_token} (OAuth) or Basic via config
# BASE_ADDRESS: https://YOUR_INSTANCE.service-now.com

DEFINE ROUTE ServiceNowRestApi WITH TYPE REST_API
    ADD REST_API_CONFIG
        WITH BASE_ADDRESS "https://YOUR_INSTANCE.service-now.com"
        WITH ENABLE_CLIENT "true"
        WITH USE_SSL "true"
        WITH REQUEST_TIMEOUT '60'
        WITH DEFAULT_CONTENT_TYPE "application/json"
    ADD EVENT Listincidents
        WITH SOURCE_TOPIC "itsm/servicenow/incident/list"
        WITH DESTINATION_TOPIC "itsm/servicenow/incident/list/response"
        WITH METHOD "GET"
        WITH ENDPOINT "/api/now/table/incident?sysparm_limit={value.json.sysparm_limit}"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Authorization" "Bearer {value.json.access_token}"
    ADD EVENT Createincident
        WITH SOURCE_TOPIC "itsm/servicenow/incident/create"
        WITH DESTINATION_TOPIC "itsm/servicenow/incident/create/response"
        WITH METHOD "POST"
        WITH ENDPOINT "/api/now/table/incident"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Content-Type" "application/json"
            ADD "Authorization" "Bearer {value.json.access_token}"
        WITH BODY "{payload}"
    ADD EVENT Postinboundevent
        WITH SOURCE_TOPIC "itsm/servicenow/em/inbound_event"
        WITH DESTINATION_TOPIC "itsm/servicenow/em/inbound_event/response"
        WITH METHOD "POST"
        WITH ENDPOINT "/api/sn_em_connector/em/inbound_event?source={value.json.source}"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Content-Type" "application/json"
            ADD "Authorization" "Bearer {value.json.access_token}"
        WITH BODY "{payload}"
    ADD EVENT Patchcmdbci
        WITH SOURCE_TOPIC "itsm/servicenow/cmdb_ci/patch"
        WITH DESTINATION_TOPIC "itsm/servicenow/cmdb_ci/patch/response"
        WITH METHOD "PATCH"
        WITH ENDPOINT "/api/now/table/cmdb_ci/{value.json.sys_id}"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Content-Type" "application/json"
            ADD "Authorization" "Bearer {value.json.access_token}"
        WITH BODY "{payload}"
    ADD EVENT Listsctasks
        WITH SOURCE_TOPIC "itsm/servicenow/sc_task/list"
        WITH DESTINATION_TOPIC "itsm/servicenow/sc_task/list/response"
        WITH METHOD "GET"
        WITH ENDPOINT "/api/now/table/sc_task?sysparm_query={value.json.sysparm_query}"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Authorization" "Bearer {value.json.access_token}"
```

## Events

| Event | Method | Endpoint | Request topic | Response topic |
| - | - | - | - | - |
| Listincidents | GET | `/api/now/table/incident?sysparm_limit=` | `itsm/servicenow/incident/list` | `itsm/servicenow/incident/list/response` |
| Createincident | POST | `/api/now/table/incident` | `itsm/servicenow/incident/create` | `itsm/servicenow/incident/create/response` |
| Postinboundevent | POST | `/api/sn_em_connector/em/inbound_event?source=` | `itsm/servicenow/em/inbound_event` | `itsm/servicenow/em/inbound_event/response` |
| Patchcmdbci | PATCH | `/api/now/table/cmdb_ci/{sys_id}` | `itsm/servicenow/cmdb_ci/patch` | `itsm/servicenow/cmdb_ci/patch/response` |
| Listsctasks | GET | `/api/now/table/sc_task?sysparm_query=` | `itsm/servicenow/sc_task/list` | `itsm/servicenow/sc_task/list/response` |

## Auth

**OAuth 2.0 Bearer — default in the template:**

1. Register an OAuth application on the ServiceNow instance (System OAuth → Application Registry).
2. Obtain an `access_token`.
3. Set connector `BASE_ADDRESS` to `https://{instance}.service-now.com`.
4. Pass `access_token` on the MQTT request payload so headers resolve:
   * `Authorization: Bearer {value.json.access_token}`
5. Store the token in Hub secrets / `GET SECRET`. Never commit real credentials.

**Basic (username / password):**

1. Create an integration user with roles for Table API / Event Management as needed (e.g. `itil`, `rest_service`, EM connector roles).
2. Prefer `WITH USERNAME "integration.user"` and `WITH PASSWORD GET SECRET "SERVICENOW_PASSWORD"` on `REST_API_CONFIG` (remove Bearer header lines if using config Basic).

## Example payloads

**Create incident from alarm:**

```json theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
{
  "access_token": "YOUR_ACCESS_TOKEN",
  "short_description": "Line sensor fault — Zone A",
  "description": "Vibration above threshold at 2026-10-04T00:00:00Z",
  "urgency": "2",
  "impact": "2",
  "category": "Hardware"
}
```

**EM inbound event:**

```json theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
{
  "access_token": "YOUR_ACCESS_TOKEN",
  "source": "genericJson",
  "event_class": "IIoTAlarm",
  "node": "plc-line-a",
  "type": "High Vibration",
  "resource": "ZoneA/Sensor01",
  "severity": "3",
  "description": "Vibration above threshold"
}
```

**PATCH CMDB CI:**

```json theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
{
  "access_token": "YOUR_ACCESS_TOKEN",
  "sys_id": "a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6",
  "operational_status": "2",
  "short_description": "Updated from Coreflux telemetry"
}
```

**List sc\_task:**

```json theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
{
  "access_token": "YOUR_ACCESS_TOKEN",
  "sysparm_query": "state=1^ORDERBYnumber"
}
```

## Deploy notes

* Deploy **`ServiceNowRestApi.lot` only** (`-addRoute`). Do **not** deploy `hub-metadata.lot` as a connector — it exists for Hub / `-listTemplates` (`ADD METADATA` + `WITH IMAGE` base64).
* Hub category: **REST API Connectors**.
* Doc link: [https://docs.coreflux.org/latest/lot-language/routes/rest-api-apps/servicenow](https://docs.coreflux.org/latest/lot-language/routes/rest-api-apps/servicenow)

## Related

* [REST API Connectors](/latest/lot-language/routes/rest-api-routes)
* [REST API Apps catalog](/latest/lot-language/routes/rest-api-apps)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.