GraphQL API

Use the Panther GraphQL API to interact with your Panther entities

Overview

Panther offers a public GraphQL-over-HTTP API, meaning you can write GraphQL queries and invoke the API using a typical HTTP request. For more information on GraphQL, see GraphQL's documentation.

Currently, you can interact with the following entities through the GraphQL API:

Additional operations are available in the REST API.

Understanding a GraphQL query

Click to expand GraphQL query example

The example query below is named ListAlerts. This query will return a list of alerts including every alert's id, title, severity and status based on the time range provided.

  • The input variable of type AlertsInput is used to filter the alerts based on certain conditions, such as createdAtAfter and createdAtBefore. Those conditions will provide a time range for the query.

  • The alerts field returns an object with edges and pageInfo. Each edge has a node field that contains the actual alert data, such as id, title, severity and status.

  • The pageInfo field contains information on pagination, such as hasNextPage and endCursor, which allows the user to loop through all the pages of alerts once hasNextPage becomes false.

query ListAlerts($input: AlertsInput!) {
    alerts(input: $input) {
      edges {
        node {
          id
          title
          severity
          status
        }
      }
      pageInfo {
        hasNextPage
        endCursor
      }
    }
  }

Discover the Panther GraphQL schema

There are three ways to discover the GraphQL schema:

  • Option 1 (quickest): Download the publicly available GraphQL schema file

  • Option 2 (most user-friendly): Use Panther's API Playground

  • Option 3 (best for tools and services): Perform an introspection query against the GraphQL endpoint

Option 1: Download the publicly available GraphQL schema file

You can download the latest version of the GraphQL schema file here.

How to use the Panther GraphQL API

Step 1: Identify your Panther GraphQL API URL

To locate your GraphQL API URL:

  • In the upper-right corner of your Panther Console, click the gear icon, then API Tokens.

    • At the top of the page, see the API URL.

    • The GraphQL API URL structure differs depending on your Panther deployment model:

      • SaaS deployments: https://api.{YOUR_PANTHER_DOMAIN}.runpanther.net/public/graphql

      • Cloud Connected and self-hosted deployments: https://{YOUR_PANTHER_DOMAIN}/v1/public/graphql

Step 2: Generate an API token

Step 3: Invoke the Panther GraphQL API

In addition to testing with the API Playground, there are two ways to invoke a GraphQL-over-HTTP API:

  • Option 1 (recommended): Install and use a GraphQL Client to abstract the transport-related complexities

  • Option 2: Manually construct an HTTP call

While all GraphQL operations are essentially simple HTTP calls, the advantage of using a GraphQL client is that it is more user-friendly.

We recommend using:

Below are some examples of how you would construct a GraphQL query to fetch the first page of alerts in your system:

// npm install graphql graphql-request

import { GraphQLClient, gql } from 'graphql-request';

const client = new GraphQLClient(
  'YOUR_PANTHER_API_URL', 
  { headers: { 'X-API-Key': 'YOUR_API_KEY' } 
});

// `PaginateAlerts` is a nickname for the operation
const query = gql` 
  query PaginateAlerts {
  alerts(
  input: {
    createdAtAfter: "2023-06-14T21:00:00Z",
    createdAtBefore: "2023-06-21T21:59:59Z"
  }) {
    edges {
      node {
        id
        title
        severity
        status
      }
    }
    pageInfo {
      hasNextPage
      endCursor
    }
  }
}
`;

client.request(query).then((data) => console.log(data));

Last updated