---
title: NerdGraph tutorial: Issue and alert event query APIs
source: https://docs.newrelic.com/docs/apis/nerdgraph/examples/nerdgraph-issues-api-via-github
---

This page is a place for you and your team to learn how to query your data for issues and incidents and then configure features using our NerdGraph API.

Our two main data types are `Issue Type` and `Incident Type`.

## Issue Type [#issue-type]

You can learn more about data types of New Relic here:

| Name             | Type               | Description                                                                                                                                                                                     |
| ---------------- | ------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `accountIds`     | [Int!]!            | A list of account Ids. As an issue could be correlated with others from other accounts.                                                                                                         |
| `acknowledgedAt` | EpochMilliseconds  | The time the issue was acknowledged.                                                                                                                                                            |
| `acknowledgedBy` | String             | The user that acknowledged the issue.                                                                                                                                                           |
| `activatedAt`    | EpochMilliseconds  | The time the issue was activated: createdAt + gracePeriod.                                                                                                                                      |
| `closedAt`       | EpochMilliseconds  | The time the issue was closed.                                                                                                                                                                  |
| `closedBy`       | String             | The user that manually closed the issue.                                                                                                                                                        |
| `createdAt`      | EpochMilliseconds  | The time the issue was created.                                                                                                                                                                 |
| `description`    | [String!]!         | A list of incident descriptions.                                                                                                                                                                |
| `entityGuids`    | [EntityGuid!]      | A list of unique entity identifiers.                                                                                                                                                            |
| `entityNames`    | [String!]          | A list of entity names.                                                                                                                                                                         |
| `entityTypes`    | [String!]          | A list of entity types.                                                                                                                                                                         |
| `environmentId`  | [Int!]!            | See [overview of alerts](https://docs.newrelic.com/docs/alerts-applied-intelligence/applied-intelligence/incident-intelligence/get-started-incident-intelligence/) to learn about environments. |
| `eventType`      | String!            | An issue event that could be `INCIDENT_ADDED`, `USER_ACTION`, `INCIDENT_CLOSED`, etc.                                                                                                           |
| `incidentIds`    | [String!]          | A list of incident IDs in this issue. In some cases there may be thousands of incidents in an issue.                                                                                            |
| `isCorrelated`   | Boolean!           | True means that other issues were correlated to this one.                                                                                                                                       |
| `isIdle`         | Boolean!           | See our documentation to learn about idle issues.                                                                                                                                               |
| `issueId`        | ID!                | Issue identifier.                                                                                                                                                                               |
| `origins`        | [String!]!         | A list of origins of incidents like incidents, anomalies, and external.                                                                                                                         |
| `priority`       | Priority!          | The issue priority. Can be one of: `LOW`, `MEDIUM`, `HIGH`, `CRITICAL`.                                                                                                                         |
| `sources`        | [String!]!         | A list of sources of the incidents like newrelic or external.                                                                                                                                   |
| `state`          | IssueState!        | Issue state can be one of: `CREATED`, `ACTIVATED`, `DEACTIVATED`, `CLOSED`.                                                                                                                     |
| `title`          | [String!]!         | A list of underlying incident titles.                                                                                                                                                           |
| `totalIncidents` | Int!               | The count of underlying incidents.                                                                                                                                                              |
| `updatedAt`      | EpochMilliseconds! | The time the issue was last updated.                                                                                                                                                            |

## Issue lifecycle and state [#issue-lifecycle]

Idle issues:

-   An issue can become idle if it is too big, meaning it contains 5000 incidents or more.
-   An idle issue does not accept any more incidents.
-   An idle issue will not correlate to other issues.

## Incident type [#incident-type]

| Field               | Type              | Description                                                                                                                                                                                    |
| ------------------- | ----------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `accountIds`        | String            | An account id this incident is stored in.                                                                                                                                                      |
| `closedAt`          | EpochMilliseconds | The time the incident was closed.                                                                                                                                                              |
| `createdAt`         | EpochMilliseconds | The time the incident was created.                                                                                                                                                             |
| `description`       | String            | The description is generated from the policy name and the condition name or provided through API.                                                                                              |
| `entityGuids`       | EntityGuid        | An unique entity identifier.                                                                                                                                                                   |
| `entityNames`       | String            | An entity name.                                                                                                                                                                                |
| `entityTypes`       | String            | An entity type.                                                                                                                                                                                |
| `environmentId`     | Int!              | See [our documentation](https://docs.newrelic.com/docs/alerts-applied-intelligence/applied-intelligence/incident-intelligence/get-started-incident-intelligence/) to learn about environments. |
| `incidentId`        | ID                | Incident identifier.                                                                                                                                                                           |
| `priority`          | Priority          | Incident priority. Can be one of: `LOW`, `MEDIUM`, `HIGH`, `CRITICAL`.                                                                                                                         |
| `state`             | IncidentState.    | Incident state. Can be one of:`CREATED`, `CLOSED`.                                                                                                                                             |
| `timestamp`         | EpochMilliseconds | Incident event timestamp.                                                                                                                                                                      |
| `title`             | String            | The description the user gave the condition if provided.                                                                                                                                       |
| `updatedAt`         | EpochMilliseconds | The time the incident was last updated.                                                                                                                                                        |
| `anomalyId`         | Optional          | If this incident originated from a New Relic anomaly it will have an anomaly ID.                                                                                                               |
| `conditionFamilyId` | Optional          | The condition id                                                                                                                                                                               |
| `policyIds`         | String            | The Id of the policy that generated this incident.                                                                                                                                             |
| `aggregationTags`   | [KeyValue!]       | Aggregation of tags related to this incident.                                                                                                                                                  |

## List and filter issues [#list-filter-issues]

The `issues` query allows you to paginate through all of your issues per account. It also allows some filtering functionality on the issues.

**List issues**

If you don't provide any filtering data, you will get the issue data for the last 24 hours.

### Request

````graphql
{
  actor {
    account(id: ACCOUNT_ID) {
      aiIssues {
        issues {
          issues {
            issueId
            priority
            state
            title
          }
        }
      }
    }
  }
}
```

### Results

```json
{
  "data": {
    "actor": {
      "account": {
        "aiIssues": {
          "issues": {
            "issues": [
              {
                "issueId": "f0668430-60c4-4bfd-8188-fcbeefb1d5ca",
                "priority": "CRITICAL",
                "state": "CREATED",
                "title": [
                  "NrAiIncident query result is > 30.0 for 1 minutes on 'ROI test for photon with checkbox'"
                ]
              },
              {
                "issueId": "12427573-fe89-4be1-9411-30158e0a9874",
                "priority": "MEDIUM",
                "state": "CLOSED",
                "title": [
                  "Anomaly: It was different from normal"
                ]
              },
              {
                "issueId": "2b3fcffe-5330-4766-bc51-392b6db5eedc",
                "priority": "MEDIUM",
                "state": "CLOSED",
                "title": [
                  "Anomaly: It was different from normal"
                ]
              },
```

````

**Cursor pagination**

Note that the maximum number of issues that can be returned through pagination is set by the NRQL [`LIMIT` MAX](/docs.newrelic.com/docs/nrql/nrql-syntax-clauses-functions/#sel-limit), and filtering will be required if this limit is exceeded.

### Initial Request

````graphql
{
  actor {
    account(id: YOUR_ACCOUNT_ID) {
      aiIssues {
        issues(cursor: "") {
          issues {
            issueId
            priority
            state
            title
          }
          nextCursor
        }
      }
    }
  }
}
```

### Initial Results

```json
{
  "data": {
    "actor": {
      "account": {
        "aiIssues": {
          "issues": {
            "issues": [
              {
                "issueId": "bda33b52-c70b-47b9-abe3-9e859a394037",
                "priority": "CRITICAL",
                "state": "ACTIVATED",
                "title": [
                  "Signal lost for 5 minutes on 'Percent All Facet'"
                ]
              },
              {
                "issueId": "242c713c-7654-491c-808e-3aa7fc44812b",
                "priority": "MEDIUM",
                "state": "CREATED",
                "title": [
                  "Anomaly: Non-web throughput"
                ]
              },
              {
                "issueId": "f19c9803-fb24-4d5d-9c35-16f659bceb3a",
                "priority": "MEDIUM",
                "state": "CLOSED",
                "title": [
                  "Anomaly: Error rate"
                ]
              }
            ],
            "nextCursor": "=ATN"
          }
        }
      }
    }
  },
```

Then, in your subsequent request, provide the cursor value from `nextCursor` previous reply, until the `nextCursor` is empty.

The subsequent request should like:

```graphql
{
  actor {
    account(id: YOUR_ACCOUNT_ID) {
      aiIssues {
        issues(cursor: "=ATN") {
          issues {
            issueId
            priority
            state
            title
          }
          nextCursor
        }
      }
    }
  }
}
```

````

**Filter issues**

Filter issues by entity guids, entity types, issues priority or issues states or any combination of those attributes.

````graphql
"Filter issues"
input FilterIssues {
  "entityGuids"
  entityGuids: [EntityGuid!]
  "entityTypes"
  entityTypes: [String!]
  "ids"
  ids: [ID!]
  "priority"
  priority: [String!]
  "states"
  states: [IssueState!]
}
```

Here `entityGuides` and `entityTypes` are entity attributes defined in [Learn about New Relic entities](/docs/new-relic-solutions/new-relic-one/core-concepts/what-entity-new-relic/) page.

* Issue priority could be one of the following: `LOW`, `MEDIUM`, `HIGH`, `CRITICAL`
* Issue states could be one of the following:  `CREATED`, `ACTIVATED`, `DEACTIVATED`, `CLOSED`
* `timeWindow` with start and end times in EpochMilliseconds format. If it is not provided the default value is the last 24 hours
* And `cursor` as we have seen already

Let's find issues with priority `CRITICAL` and state `CLOSED`:

```graphql
{
  actor {
    account(id: YOUR_ACCOUNT_ID) {
      aiIssues {
        issues(filter: {priority: "CRITICAL", states: CLOSED}) {
          issues {
            issueId
            priority
            state
            title
          }
          nextCursor
        }
      }
    }
  }
}
```

### Results

```json
{
  "data": {
    "actor": {
      "account": {
        "aiIssues": {
          "issues": {
            "issues": [
              {
                "issueId": "5948472b-f7dd-4a6e-aec0-de0390732495",
                "priority": "CRITICAL",
                "state": "CLOSED",
                "title": [
                  "team_store_validation_error query result is > 0.0 on 'Team Store Domain Specific Validation Error'"
                ]
              },
              {
                "issueId": "570c2770-efd2-4c0f-8dc8-fbc1ae69a4df",
                "priority": "CRITICAL",
                "state": "CLOSED",
                "title": [
                  "PageViewTiming query deviated from the baseline at least once in 5 minutes on 'Onyx_check_Mark test'"
                ]
              },
              {
                "issueId": "d056be64-829e-4a83-bfb1-e3232eb3a59b",
                "priority": "CRITICAL",
                "state": "CLOSED",
                "title": [
                  "Transaction query result is > 2.0 on 'Error fetching commitments (TF)'"
                ]
              },
```

The results can be further filtered by `entityGuid`.

```graphql
{
  actor {
    account(id: 1) {
      aiIssues {
        issues(filter: {priority: "CRITICAL", states: CLOSED, 
          entityGuids: ["MXxBUE18QVBQTElDQVRJT058MzIxNjY2NA", "MXxBUE18QVBQTElDQVRJT058MzIxNzY1NA"]}) {
          issues {
            entityTypes
            entityNames
            entityGuids
            issueId
            priority
            state
            title
          }
          nextCursor
        }
      }
    }
  }
}
```

### Results

```json
{
  "data": {
    "actor": {
      "account": {
        "aiIssues": {
          "issues": {
            "issues": [
              {
                "entityGuids": [
                  "MXxBUE18QVBQTElDQVRJT058MzIxNjY2NA",
                  "MXxBUE18QVBQTElDQVRJT058MzIxNzY1NA"
                ],
                "entityNames": [
                  "hour-timeslice-writer (eu-production)",
                  "metric-timeslice-service (eu-production)"
                ],
                "entityTypes": [
                  "Application"
                ],
                "issueId": "1a3a0581-aefc-4027-91a0-a941072101c0",
                "priority": "CRITICAL",
                "state": "CLOSED",
                "title": [
                  "'Custom/CassandraClient/hour_timeslice_cluster_main/percentile/95th' > 0.5 for at least 5 minutes on 'hour-timeslice-writer (eu-production)'",
                  "'Custom/CassandraClient/hour_timeslice_cluster_main/percentile/95th' > 0.5 for at least 5 minutes on 'metric-timeslice-service (eu-production)'"
                ]
              },
              {
                "entityGuids": [
                  "MXxBUE18QVBQTElDQVRJT058MzIxNzY1NA"
                ],
                "entityNames": [
                  "metric-timeslice-service (eu-production)"
                ],
                "entityTypes": [
                  "Application"
                ],
                "issueId": "fd5fda9e-6bfe-469a-8cf7-822986401033",
                "priority": "CRITICAL",
                "state": "CLOSED",
                "title": [
                  "'Custom/CassandraClient/hour_timeslice_cluster_main/percentile/95th' > 0.5 for at least 5 minutes on 'metric-timeslice-service (eu-production)'"
                ]
              }
            ],
            "nextCursor": null
          }
```

````

**Find issues by ID**

NerdGraph also lets you query by issue ID.

### Request

````graphql
{
  actor {
    account(id: 1) {
      aiIssues {
        issues(filter: {ids: ["e506476f-d804-4e5c-92b5-da8db622f10d", 
        "1bd514d9-2682-4366-8f28-5d742fd000af"]}) {
          issues {
            entityTypes
            entityNames
            entityGuids
            issueId
            priority
            state
            title
          }
          nextCursor
        }
      }
    }
  }
}
```

### Results

```json
{
  "data": {
    "actor": {
      "account": {
        "aiIssues": {
          "issues": {
            "issues": [
              {
                "entityGuids": [
                  ""
                ],
                "entityNames": [
                  "Metric query"
                ],
                "entityTypes": [
                  "Query"
                ],
                "issueId": "e506476f-d804-4e5c-92b5-da8db622f10d",
                "priority": "CRITICAL",
                "state": "CLOSED",
                "title": [
                  "Metric query result is > 1.4 for 1 minutes on 'Hillel March Demo'"
                ]
              },
              {
                "entityGuids": [
                  "MXxFWFR8U0VSVklDRXw1ODIzMTc1ODk4Mjc1OTI4Mjk5"
                ],
                "entityNames": [
                  "clm-10"
                ],
                "entityTypes": [
                  "Query"
                ],
                "issueId": "1bd514d9-2682-4366-8f28-5d742fd000af",
                "priority": "CRITICAL",
                "state": "CLOSED",
                "title": [
                  "clm-10 query result is > 30.0 for 7 minutes on 'SPIKE: signal-accumulation-service (production) — Kafka lag'"
                ]
              }
            ],
            "nextCursor": null
          }
        }
```

````

## List and filter issue events [#list-filter-issue-events]

The `issuesEvents` query allows you to paginate through all of your issues events per account. It also allows some filtering functionality on the issues events.

**List issues events**

If you don't provide any filtering data, you will get the issue events data for the last 24 hours.

### Request

````graphql
{
  actor {
    account(id: YOUR_ACCOUNT_ID) {
      aiIssues {
        issuesEvents {
          issues {
            issueId
            priority
            state
            title
            eventType
          }
        }
      }
    }
  }
}
```

### Results

```json
{
  "data": {
    "actor": {
      "account": {
        "aiIssues": {
          "issuesEvents": {
            "issues": [
              {
                "eventType": "ATTRIBUTES_UPDATED",
                "issueId": "e6da1499-cb1c-4522-bb04-6fdb487e8e2b",
                "priority": "CRITICAL",
                "state": "ACTIVATED",
                "title": [
                  "notification-request-builder query result is < 10.0 for 1 minutes on 'error logs in nrb'",
                  "notification-request-builder query result is > 1600.0 for 5 minutes on 'nrb debug logs'"
                ]
              },
              {
                "eventType": "ATTRIBUTES_UPDATED",
                "issueId": "e6da1499-cb1c-4522-bb04-6fdb487e8e2b",
                "priority": "CRITICAL",
                "state": "ACTIVATED",
                "title": [
                  "notification-request-builder query result is < 10.0 for 1 minutes on 'error logs in nrb'",
                  "notification-request-builder query result is > 1600.0 for 5 minutes on 'nrb debug logs'"
                ]
              },
              {
                "eventType": "ATTRIBUTES_UPDATED",
                "issueId": "e6da1499-cb1c-4522-bb04-6fdb487e8e2b",
                "priority": "CRITICAL",
                "state": "ACTIVATED",
                "title": [
                  "notification-request-builder query result is < 10.0 for 1 minutes on 'error logs in nrb'",
                  "notification-request-builder query result is > 1600.0 for 5 minutes on 'nrb debug logs'"
                ]
              },
              {
                "eventType": "INCIDENT_ADDED",
                "issueId": "e6da1499-cb1c-4522-bb04-6fdb487e8e2b",
                "priority": "CRITICAL",
                "state": "ACTIVATED",
                "title": [
                  "notification-request-builder query result is < 10.0 for 1 minutes on 'error logs in nrb'",
                  "notification-request-builder query result is > 1600.0 for 5 minutes on 'nrb debug logs'"
                ]
              },

```

````

**Filter issue events**

Filter issue events by `entityGuids`, `entityTypes`, issues priority or issue states or any combination of those attributes.

````graphql
"Filter issues events"
input FilterIssuesEvents {
  "entityGuids"
  entityGuids: [EntityGuid!]
  "entityTypes"
  entityTypes: [String!]
  "ids"
  ids: [ID!]
}
```

* `timeWindow` with start and end times in `EpochMilliseconds` format. If it's not provided, the default value is the last 24 hours
* And `cursor` as we have seen already

Let's find `issuesEvents` for a specific `issueId`.

```graphql
{
  actor {
    account(id: YOUR_ACCOUNT_ID) {
      aiIssues {
        issuesEvents(filter: {ids: "fe0d512f-36c7-4b7a-8a80-4c47c040807a"}) {
          issues {
            issueId
            priority
            state
            title
            eventType
            entityGuids
          }
        }
      }
    }
  }
}
```

<DNT>
  **Results**
</DNT>

```json
{
  "data": {
    "actor": {
      "account": {
        "aiIssues": {
          "issuesEvents": {
            "issues": [
              {
                "entityGuids": [
                  "MXxTWU5USHxNT05JVE9SfGUyMzA0MjczLTQzNjUtNDRlZS1iODcxLTM5MGRhNDc1ODUxNA"
                ],
                "eventType": "ATTRIBUTES_UPDATED",
                "issueId": "fe0d512f-36c7-4b7a-8a80-4c47c040807a",
                "priority": "CRITICAL",
                "state": "ACTIVATED",
                "title": [
                  "Test for alert emails query result is > 1.0 for 1 minutes on 'Matan email condition'"
                ]
              },
              {
                "entityGuids": [
                  "MXxTWU5USHxNT05JVE9SfGUyMzA0MjczLTQzNjUtNDRlZS1iODcxLTM5MGRhNDc1ODUxNA"
                ],
                "eventType": "STATE_CHANGE",
                "issueId": "fe0d512f-36c7-4b7a-8a80-4c47c040807a",
                "priority": "CRITICAL",
                "state": "ACTIVATED",
                "title": [
                  "Test for alert emails query result is > 1.0 for 1 minutes on 'Matan email condition'"
                ]
              },
              {
                "entityGuids": [
                  "MXxTWU5USHxNT05JVE9SfGUyMzA0MjczLTQzNjUtNDRlZS1iODcxLTM5MGRhNDc1ODUxNA"
                ],
                "eventType": "ATTRIBUTES_UPDATED",
                "issueId": "fe0d512f-36c7-4b7a-8a80-4c47c040807a",
                "priority": "CRITICAL",
                "state": "CREATED",
                "title": [
                  "Test for alert emails query result is > 1.0 for 1 minutes on 'Matan email condition'"
                ]
              },
              {
                "entityGuids": [
                  "MXxTWU5USHxNT05JVE9SfGUyMzA0MjczLTQzNjUtNDRlZS1iODcxLTM5MGRhNDc1ODUxNA"
                ],
                "eventType": "ATTRIBUTES_UPDATED",
                "issueId": "fe0d512f-36c7-4b7a-8a80-4c47c040807a",
                "priority": "CRITICAL",
                "state": "CREATED",
                "title": [
                  "Test for alert emails query result is > 1.0 for 1 minutes on 'Matan email condition'"
                ]
              },
...
```

````

## List and filter Incidents [#list-filter-incidents]

The `incidents` query allows you to paginate through all of your incidents per account. It also allows some filtering functionality on each incident.

The following types of incidents are supported:

-   NewRelicIncident
-   AnomalyIncident
-   RestIncident

**List incidents**

If you don't provide any filtering data, you will get the incidents data for the last 24 hours.

The example below fetches `NewRelicIncident` incidents:

### Requests

````graphql
{
  actor {
    account(id: YOUR_ACCOUNT_ID) {
      aiIssues {
        incidents {
          incidents {
            priority
            state
            title
            description
            incidentId
            updatedAt
            ... on AiIssuesNewRelicIncident {
              policyIds
              conditionFamilyId
              accountIds
            }
          }
        }
      }
    }
  }
}
```

### Results

```json
{
  "data": {
    "actor": {
      "account": {
        "aiIssues": {
          "incidents": {
            "incidents": [
              {
                "accountIds": "1",
                "conditionFamilyId": "685305",
                "description": [
                  "Policy: 'Roi nov Test'. Condition: 'RB PV '"
                ],
                "incidentId": "a86493e4-2d25-4023-a9e5-975bfaae19a8",
                "policyIds": "195617",
                "priority": "HIGH",
                "state": "CREATED",
                "title": "[\"PageView query result is > 1.3 for 2 minutes on 'RB PV '\"]",
                "updatedAt": 1651058532782
              },
              {
                "accountIds": "1",
                "conditionFamilyId": "1284850",
                "description": [
                  "Policy: 'Itzik first policy'. Condition: 'error logs in nrb'"
                ],
                "incidentId": "5de80214-6444-4e0c-aaee-fb1c42fb2f23",
                "policyIds": "707052",
                "priority": "CRITICAL",
                "state": "CREATED",
                "title": "[\"notification-request-builder query result is < 10.0 for 1 minutes on 'error logs in nrb'\"]",
                "updatedAt": 1651058523473
              },
              {
                "description": [
                  "Anomaly: Error rate"
                ],
                "incidentId": "df4ba4f3-9463-4389-873f-b13efb67dca5",
                "priority": "MEDIUM",
                "state": "CREATED",
                "title": "[\"Anomaly: Error rate\"]",
                "updatedAt": 1651058478828
              },
              {
                "accountIds": "1",
                "conditionFamilyId": "685305",
                "description": [
                  "Policy: 'Roi nov Test'. Condition: 'RB PV '"
                ],
                "incidentId": "0063f153-9152-476d-b435-54cc38ce0245",
                "policyIds": "195617",
                "priority": "CRITICAL",
                "state": "CREATED",
                "title": "[\"PageView query result is > 1.3 on 'RB PV '\"]",
                "updatedAt": 1651058472738
              },
              {
                "description": [
                  "Anomaly: It was different from normal"
                ],
                "incidentId": "2cb820d1-a070-4c27-860b-fb862ecd42a7",
                "priority": "MEDIUM",
                "state": "CREATED",
                "title": "[\"Anomaly: It was different from normal\"]",
                "updatedAt": 1651058449078
              },
              {
                "accountIds": "1",
                "conditionFamilyId": "751197",
                "description": [
                  "Policy: 'slide_Test'. Condition: 'SumOf'"
                ],
                "incidentId": "07104b47-0263-4529-b27d-6aff95eecd87",
                "policyIds": "199127",
                "priority": "CRITICAL",
                "state": "CREATED",
                "title": "[\"TransactionError query result is > 3.0 on 'SumOf'\"]",
                "updatedAt": 1651058442361
              },
```

````

**Filter incidents**

### Cursor pagination

Note that the maximum number of incidents that can be returned through pagination is set by the NRQL [LIMIT MAX](/docs.newrelic.com/docs/nrql/nrql-syntax-clauses-functions/#sel-limit), and filtering will be required if this limit is exceeded.

### Filter Incidents

Filter incidents by entity guids, entity types, issues priority, or issue states or any combination of them.

````graphql
"Filter incidents"
input FilterIncidents {
  "entityGuids"
  entityGuids: [EntityGuid!]
  "entityTypes"
  entityTypes: [String!]
  "ids"
  ids: [ID!]
  "priority"
  priority: [String!]
  "states"
  states: [IncidentState!]
}
```

* `timeWindow` with start and end times in `EpochMilliseconds` format. If it is not provided the default value is the last 24 hours.
* And `cursor` as we have seen already.
* Let's find Incidents with priority `CRITICAL` and state `CREATED`.

```graphql
{
  actor {
    account(id: YOUR_ACCOUNT_ID) {
      aiIssues {
        incidents(filter: {priority: "CRITICAL", states: CREATED}) {
          incidents {
            priority
            state
            title
            description
            incidentId
            updatedAt
            ... on AiIssuesNewRelicIncident {
              policyIds
              conditionFamilyId
              accountIds
            }
          }
        }
      }
    }
  }
}

```

### Results

```json
{
  "data": {
    "actor": {
      "account": {
        "aiIssues": {
          "incidents": {
            "incidents": [
              {
                "accountIds": "1",
                "conditionFamilyId": "195908",
                "description": [
                  "Policy: 'AirMonitor ML Dashboard Staging'. Condition: 'Latency in Production'"
                ],
                "incidentId": "44630d21-9d32-4107-a308-3ed1c4f72bce",
                "policyIds": "40053",
                "priority": "CRITICAL",
                "state": "CREATED",
                "title": "[\"Metric query result is > 0.69 for 5 minutes on 'Latency in Production'\"]",
                "updatedAt": 1651059983674
              },
              {
                "accountIds": "1",
                "conditionFamilyId": "195908",
                "description": [
                  "Policy: 'AirMonitor ML Dashboard Staging'. Condition: 'Latency in Production'"
                ],
                "incidentId": "3e2b2b2a-e45b-46d6-b45d-637b74b5efda",
                "policyIds": "40053",
                "priority": "CRITICAL",
                "state": "CREATED",
                "title": "[\"Metric query result is > 0.69 for 5 minutes on 'Latency in Production'\"]",
                "updatedAt": 1651059983607
              },
              {
                "accountIds": "1",
                "conditionFamilyId": "195907",
                "description": [
                  "Policy: 'AirMonitor ML Dashboard Staging'. Condition: 'Latency in Staging'"
                ],
                "incidentId": "6e934358-d16b-494d-abb2-6300c4d96f11",
                "policyIds": "40053",
                "priority": "CRITICAL",
                "state": "CREATED",
                "title": "[\"Metric query result is > 0.69 for 5 minutes on 'Latency in Staging'\"]",
                "updatedAt": 1651059983223
              },
              {
                "accountIds": "1",
                "conditionFamilyId": "195907",
                "description": [
                  "Policy: 'AirMonitor ML Dashboard Staging'. Condition: 'Latency in Staging'"
                ],
                "incidentId": "97373770-caad-46cd-a69d-a358de3be090",
                "policyIds": "40053",
                "priority": "CRITICAL",
                "state": "CREATED",
                "title": "[\"Metric query result is > 0.69 for 5 minutes on 'Latency in Staging'\"]",
                "updatedAt": 1651059983059
              },

```

````

**Find incidents by incident ID**

The API lets you query by incident id:

### Request

````graphql
{
  actor {
    account(id: YOUR_ACCOUNT_ID) {
      aiIssues {
        incidents(filter: {ids: "97373770-caad-46cd-a69d-a358de3be090"}) {
          incidents {
            priority
            state
            title
            description
            incidentId
            updatedAt
            ... on AiIssuesNewRelicIncident {
              policyIds
              conditionFamilyId
              accountIds
            }
          }
        }
      }
    }
  }
}

```

### Result

```json
{
  "data": {
    "actor": {
      "account": {
        "aiIssues": {
          "incidents": {
            "incidents": [
              {
                "accountIds": "1",
                "conditionFamilyId": "195907",
                "description": [
                  "Policy: 'AirMonitor ML Dashboard Staging'. Condition: 'Latency in Staging'"
                ],
                "incidentId": "97373770-caad-46cd-a69d-a358de3be090",
                "policyIds": "40053",
                "priority": "CRITICAL",
                "state": "CREATED",
                "title": "[\"Metric query result is > 0.69 for 5 minutes on 'Latency in Staging'\"]",
                "updatedAt": 1651059983059
              }
            ]
          }
        }
      }
    }
  },

```

````

## List and filter incident events [#list-filter-incident-events]

The `incidentsEvents` query allows you to paginate through all of your incidents events per account. It also allows some filtering functionality on the incidents events.

**List incident events**

If you don't provide any filtering data, you will get the incidents events data for the last 24 hours.

### Request

````graphql
{
  actor {
    account(id: YOUR_ACCOUNT_ID) {
      aiIssues {
        incidentsEvents {
          incidents {
            priority
            incidentId
            state
            title
            updatedAt
            description
          }
        }
      }
    }
  }
}
```

### Results

```json
{
  "data": {
    "actor": {
      "account": {
        "aiIssues": {
          "incidentsEvents": {
            "incidents": [
              {
                "description": [
                  "Policy: 'e2e: hrr9ISoLd'. Condition: 'e2e: VceqCmtcT'"
                ],
                "incidentId": "693b7dcb-5a6b-4923-acaa-9d4e7e568ae5",
                "priority": "CRITICAL",
                "state": "CLOSED",
                "title": "[\"Provider . Burst Balance . Average < 1 at least once in 2 minutes on 'vol-03e3199dd4b4ffac4'\"]",
                "updatedAt": 1651060591602
              },
              {
                "description": [
                  "Policy: 'e2e: hrr9ISoLd'. Condition: 'e2e: VceqCmtcT'"
                ],
                "incidentId": "fb0dcb8b-052f-4056-8579-ff7cae8fa879",
                "priority": "CRITICAL",
                "state": "CLOSED",
                "title": "[\"Provider . Burst Balance . Average < 1 at least once in 2 minutes on 'vol-00163b96c3ccd2199'\"]",
                "updatedAt": 1651060587005
              },
              {
                "description": [
                  "Policy: 'AirMonitor ML Dashboard Staging'. Condition: 'Latency in Staging'"
                ],
                "incidentId": "42bcd3e2-bc2d-4a3d-9e85-ebd8597e6eba",
                "priority": "CRITICAL",
                "state": "CLOSED",
                "title": "[\"Metric query result is > 0.69 for 5 minutes on 'Latency in Staging'\"]",
                "updatedAt": 1651060560312
              },

```

````

**Filter incident events**

### Cursor pagination

In order to paginate through your data, you must include the `nextCursor` field on your initial query.

### Filter Incident Events

Filter incident events by entity guids, entity types, incident priority, or incident states or any combination of these.

````handlebars
"Filter incidents events"
input FilterIncidentsEvents {
  "entityGuids"
  entityGuids: [EntityGuid!]
  "entityTypes"
  entityTypes: [String!]
  "ids"
  ids: [ID!]
}
```

* `timeWindow` with start and end times in `EpochMilliseconds` format. If it is not provided the default value is the last 24 hours.
* And `cursor` as we have seen already.

Let's query incident events, so we can obtain their 'incidentId's:

```graphql
{
  actor {
    account(id: YOUR_ACCOUNT_ID) {
      aiIssues {
        incidentsEvents(filter: {ids: "cd512082-6ebe-46ac-a6dc-d387dc86dc80"}) {
          incidents {
            priority
            incidentId
            state
            title
            updatedAt
            description
            createdAt
            timestamp
            ... on AiIssuesNewRelicIncident {
              accountIds
              policyIds
            }
          }
        }
      }
    }
  }
}
```

### Results

```json
{
  "data": {
    "actor": {
      "account": {
        "aiIssues": {
          "incidentsEvents": {
            "incidents": [
              {
                "accountIds": "1",
                "createdAt": "1651060523109",
                "description": [
                  "Policy: 'KPT: Low-urgency'. Condition: 'Kafka broker offline'"
                ],
                "incidentId": "cd512082-6ebe-46ac-a6dc-d387dc86dc80",
                "policyIds": "80113",
                "priority": "CRITICAL",
                "state": "CREATED",
                "timestamp": 1651060523110,
                "title": "[\"Signal lost for 35 minutes on 'Kafka broker offline'\"]",
                "updatedAt": 1651060523110
              },
              {
                "accountIds": "1",
                "createdAt": "1651060523109",
                "description": [
                  "Policy: 'KPT: Low-urgency'. Condition: 'Kafka broker offline'"
                ],
                "incidentId": "cd512082-6ebe-46ac-a6dc-d387dc86dc80",
                "policyIds": "80113",
                "priority": "CRITICAL",
                "state": "CREATED",
                "timestamp": 1651060523110,
                "title": "[\"Signal lost for 35 minutes on 'Kafka broker offline'\"]",
                "updatedAt": 1651060523110
              },
              {
                "accountIds": "1",
                "createdAt": "1651060523109",
                "description": [
                  "Policy: 'KPT: Low-urgency'. Condition: 'Kafka broker offline'"
                ],
```

````

## Configure issues features [#configure-some-issues-features]

Issues service has some configuration parameters.

To get the current configuration parameters for your environment, you can run `configByEnvironment` query.

**ConfigByEnvironment query**

### Request

````graphql
{
  actor {
    account(id: YOUR_ACCOUNT_ID) {
      aiIssues {
        configByEnvironment {
          config {
            flappingInterval
            inactivePeriod
            incidentTimeout
            issueTtl
            maxIssueSize
          }
        }
      }
    }
  }
}
```

### Results

```json
{
  "data": {
    "actor": {
      "account": {
        "aiIssues": {
          "configByEnvironment": {
            "config": {
              "flappingInterval": 0,
              "gracePeriod": [
                {
                  "period": 60,
                  "priority": "CRITICAL"
                },
                {
                  "period": 300,
                  "priority": "HIGH"
                },
                {
                  "period": 600,
                  "priority": "MEDIUM"
                },
                {
                  "period": 900,
                  "priority": "LOW"
                }
              ],
              "inactivePeriod": 14400,
              "incidentTimeout": 90000,
              "issueTtl": 259200,
              "maxIssueSize": 5000
            }
          }
        }
      }
    }
  }
```

Here, each environment configuration has the following parameters:

```graphql
"Environment configuration object"
type EnvironmentConfiguration {
  "Flapping interval in seconds"
  flappingInterval: Seconds
  "Grace periods per priority"
  gracePeriod: [GracePeriodConfig!]
  "Inactive period in seconds"
  inactivePeriod: Seconds
  "Incident timeout in seconds"
  incidentTimeout: Seconds
  "Issue TTL in seconds"
  issueTtl: Seconds
  "Max incidents in the issue"
  maxIssueSize: Int
}
```

Using the corresponding `mutations`, you can also change `issueTtl` and `gracePeriod` environment configuration parameters.

* `aiIssuesUpdateIssueTtl`
* `aiIssuesUpdateGracePeriod`

### Request

```graphql
mutation {
  aiIssuesUpdateIssueTtl(accountId: YOUR_ACCOUNT_ID, issueTtl: 259200) {
    error
    config {
      flappingInterval
      gracePeriod {
        period
        priority
      }
      inactivePeriod
      incidentTimeout
      issueTtl
      maxIssueSize
    }
  }
}
```

### Results

```json
{
  "data": {
    "aiIssuesUpdateIssueTtl": {
      "config": {
        "flappingInterval": 0,
        "gracePeriod": [
          {
            "period": 60,
            "priority": "CRITICAL"
          },
          {
            "period": 300,
            "priority": "HIGH"
          },
          {
            "period": 600,
            "priority": "MEDIUM"
          },
          {
            "period": 900,
            "priority": "LOW"
          }
        ],
        "inactivePeriod": 14400,
        "incidentTimeout": 90000,
        "issueTtl": 259200,
        "maxIssueSize": 5000
      },
      "error": null
    }
  },

```

````

## Acknowledge or unacknowledge issues [#resolve-ack-issues]

Using `mutations` you can acknowledge or unacknowledge and resolve the given issue by its `issueId`.

-   aiIssuesAckIssue
-   aiIssuesResolveIssue
-   aiIssuesUnackIssue

**Acknowledge or unacknowledge issues**

### Request

````graphql
mutation {
  aiIssuesResolveIssue(accountId: 10581561, issueId: "f0846f5e-fc9d-4dc0-afdd-07cce7cc6fc4") {
    error
    result {
      action
      accountId
      issueId
      routingKey
    }
  }
}
```

### Results

```json
{
  "data": {
    "aiIssuesResolveIssue": {
      "error": null,
      "result": {
        "accountId": 10581561,
        "action": "RESOLVE",
        "issueId": "f0846f5e-fc9d-4dc0-afdd-07cce7cc6fc4",
        "routingKey": "93538a443af520d10e7999fdb183ebf21e4cb6bd"
      }
    }
```

````

## Running from the command line [#running-from-command-line]

To run queries from the command line:

1 Get your API key, fetch or create one in the [API Key UI](https://staging-one.newrelic.com/api-keys-ui).

2 Export it to your shell with `export API_KEY=my_api_key`

3 Run these examples:

> #### ⚠️ IMPORTANT
>
> You must include an experimental opt-in header in your requests. Otherwise, you get access errors like this:
>
> ```json
> {"data":{"actor":{"account":{"aiIssues":{"issues":null}}}},"errors":[{"extensions":{"errorClass":"ACCESS_DENIED","nrOnly":{}},"locations":[{"column":70,"line":1}],"message":"You must opt in to using experimental schemas by passing the 'nerd-graph-unsafe-experimental-opt-in: AiIssues' header.\n\nProviding the header indicates that you acknowlege that the field(s) you are querying are subject to breaking changes.\n","path":["actor","account","aiIssues","issues"]}]}%
> ```

**Example: list all issues**

List all Issues for the last 24 hours

### How requests look in GraphQL UI

````graphql
{
  actor {
    account(id: YOUR_ACCOUNT_ID) {
      aiIssues {
        issues {
          issues {
            issueId
            priority
            state
            title
          }
        }
      }
    }
  }
}
```

### From the command line the same request

```json
{
  "data": {
    "aiIssuesResolveIssue": {
      "error": null,
      "result": {
        "accountId": 10581561,
        "action": "RESOLVE",
        "issueId": "f0846f5e-fc9d-4dc0-afdd-07cce7cc6fc4",
        "routingKey": "93538a443af520d10e7999fdb183ebf21e4cb6bd"
      }
    }
```

### Results

```json
{
  "data": {
    "actor": {
      "account": {
        "aiIssues": {
          "issues": {
            "issues": [
              {
                "issueId": "eb152a9f-def7-45bd-9b3f-34ec61ef8c82",
                "priority": "MEDIUM",
                "state": "CREATED",
                "title": [
                  "Anomaly: It was different from normal"
                ]
              },
              {
                "issueId": "9ae6a86a-582f-4102-8757-ee11c1a20dfc",
                "priority": "HIGH",
                "state": "CREATED",
                "title": [
                  "Web throughput < 50 for at least 5 minutes on 'error-group-control-plane (staging)'"
                ]
              },
              {
                "issueId": "e19aa2d0-2b12-4148-aedd-848577e9c4fc",
                "priority": "CRITICAL",
                "state": "CREATED",
                "title": [
                  "clm-10 query result is > 1.0 for 15 minutes on 'NO_CONSUMER'"
                ]
              },
              {
                "issueId": "9184ab3c-4e45-4bc9-b2a5-f78c23a13197",
                "priority": "MEDIUM",
                "state": "CREATED",
                "title": [
                  "Anomaly: It was different from normal"
                ]
              },
              {
                "issueId": "e2d05a25-2a7e-4b3c-b5bf-8a236f2a0360",
                "priority": "MEDIUM",
                "state": "CREATED",
                "title": [
                  "Anomaly: It was different from normal"
                ]
              },
              {
                "issueId": "b478bd0e-baa1-42ed-8911-d32249d45010",
                "priority": "CRITICAL",
                "state": "ACTIVATED",
                "title": [
                  "PageViewTiming query deviated from the baseline at least once in 5 minutes on 'Onyx_check_Mark test'"
                ]
              },
              {
                "issueId": "f672153a-262b-4405-85a7-874709ed21ff",
                "priority": "MEDIUM",
                "state": "CREATED",
                "title": [
                  "Anomaly: It was different from normal"
                ]
              },
              ...
```

````
