---
title: "Query examples for events subscription"
slug: "query-examples-for-events-subscription"
abstract: "Create, update and delete events subscription using GraphQL"
---
# Query examples for events subscription

You can perform events subscription with subscription operations for the following GraphQL types:

- Item
- Job
- Publishing

For a complete list of available types and operations, refer to the built-in documentation in the GraphQL IDE.

## Enable WebSocket on IIS

Graphql subscription requires WebSocket for two ways communication.

To turn on the WebSocket feature in Windows Internet Information Services and authenticate with access token:

1. In the Control Panel, open **Windows Features** and enable the WebSocket Protocol feature.

    ![The Windows Features dialog](https://doc.sitecore.com/api/markdown-image/xp/en/developers/105/sitecore-experience-manager/images/windowson.png)

2. After the features have been enabled, go to IIS on Windows, then click on the root Site.
3. Under **Management**, click on **Configuration Editor**.
4. In the **Section** dropdown box, type "system.webServer/webSocket", then to the right, click **Unlock Section**.

    ![The Configuration Editor](https://doc.sitecore.com/api/markdown-image/xp/en/developers/105/sitecore-experience-manager/images/websocket.png)

5. Add the following in **SitecoreCMInstance** `web.config`:

    ```xml
    <system.webServer>
       <webSocket enabled="true" />
    </system.webServer>
    ```

6. Create an [access token](https://doc.sitecore.com/xp/en/developers/105/sitecore-experience-manager/walkthrough--enabling-and-authorizing-requests-to-the-authoring-and-management-api.html#UUID-0d300dda-55bf-01f0-6762-33ec87516f7a_section-idm1403337571915802 "Obtain an access token").
7. Use your access token when creating a WebSocket GraphQL client in NodeJS with graphql-ws to connect to your Authoring endpoint, as in the following example:

    ```csharp
    import { createClient } from "graphql-ws";

    export const wsClient = createClient({
      url: "wss://{cm_instance_url}/sitecore/api/authoring/graphql/v1",
      connectionParams: () => ({
        access_token: `{access_token}`
      }),
      on: {
        connecting: () => console.log(" Connecting WS..."),
        connected: () => console.log(" WebSocket connected"),
        closed: (e) => console.log(" WebSocket closed:", e),
        error: (e) => console.log(" Full keys:", e)
      }
    });
    ```

## Query examples for Item

The following sections contain example queries for events subscription.

### On Item Added

You can receive the “on item added” event data with an onItemAdded subscription.

#### Query { .notintoc }

```csharp
subscription {
 onItemAdded(input: { database: "master"}) {
   name
   displayName
   path
   }
 }

```

#### Result { .notintoc }

```

Data:
  onItemAdded:
  displayName: "test item"
  itemId: "5f18db1b7afa43e99b6c84f7a0cb3bd8"
  name: "test item"
  path: "/sitecore/content/Home/test item"

```

### On Job Started { .notintoc }

You can receive the “on job started” event data with an onJobStarted subscription.

#### Query { .notintoc }

```csharp
subscription {
   onJobStarted(input: { jobName: "Sitecore.ListManagement.Operations.UpdateListOperationsAgent" }) {
   name
   jobState
   expiry
   done
   category
   queueTime
   handle
   siteName
   displayName
   }
   }

```

#### Result { .notintoc }

```

Data:
  onJobStarted:
    category: "schedule"
    displayName: "Sitecore.ListManagement.Operations.UpdateListOperationsAgent"
    done: true   expiry: "2025-12-15T11:`35:29`.216Z"
    handle: "cef968ae-ba25-46ae-b06e-4020c2b84ba1"
    jobState: "Finished"
    name: "Sitecore.ListManagement.Operations.UpdateListOperationsAgent"
    queueTime: "2025-12-15T11:`34:29`.215Z"
    siteName: "scheduler"

```

### Publishing Status Updated { .notintoc }

You can receive the “publishingStatusUpdated” event data with a publishingStatusUpdated subscription.

#### Query { .notintoc }

```csharp
subscription {
   publishingStatusUpdated(input: { operationId: "1bac04b7-8b97-4756-b0c9-38dcacc89b5b " })   {
   isDone
   isFailed
   state
   processed
   }
   }

```

#### Result { .notintoc }

```

Data:
  publishingStatusUpdated:
    isDone: true
    isFailed: false
    processed: 104
    state: "Finished"

```