# Fetching Logs Programmatically

You can fetch logs for your instances, connections, data sources, and other Prismatic resources programmatically using the [events](https://prismatic.io/docs/api/schema/queries.md#events)) query. An event currently represents a log entry, and may represent additional resources (such as step results) in the future. To filter for log entries specifically, pass `typeIn: [LOG_EVENT]` to the query.

## Querying logs[​](#querying-logs "Direct link to Querying logs")

Use the `events` query with `typeIn: [LOG_EVENT]` to fetch log entries. Because `Event` is a union type, use an inline fragment (`... on LogEvent`) to select log-specific fields:

Fetch Log Events

```graphql
query FetchLogs($timestampGte: DateTime!, $timestampLte: DateTime!) {
  events(
    typeIn: [LOG_EVENT]
    orderBy: { field: TIMESTAMP, direction: DESC }
    timestampGte: $timestampGte
    timestampLte: $timestampLte
  ) {
    nodes {
      id
      timestamp
      ... on LogEvent {
        logType
        message
        flowName
        severity
        instanceId
        instanceName
        customerName
        integrationName
        instanceType
        executionResultId
        requiredConfigVariableKey
      }
    }
    pageInfo {
      hasNextPage
      endCursor
    }
  }
}

```

Query Variables

```json
{
  "timestampGte": "2026-04-22T00:15:30.726000+00:00",
  "timestampLte": "2026-04-22T16:15:28.510000+00:00"
}

```

Queries are time-boxed

If you omit either `timestampGte` or `timestampLte`, the query is time-boxed to a two-hour range by default. If you specify neither argument, the query returns logs from the past two hours. To query a longer window, supply both timestamps explicitly.

### LogEvent fields[​](#logevent-fields "Direct link to LogEvent fields")

The fields available on a `LogEvent` node include:

| Field                       | Description                                                                                                                                            |
| --------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `id`                        | The unique identifier for the event.                                                                                                                   |
| `timestamp`                 | The time the log entry was recorded.                                                                                                                   |
| `logType`                   | The source of the log: `EXECUTION`, `CONNECTION`, `DATA_SOURCE`, `MANAGEMENT`, or `RATE_LIMIT`.                                                        |
| `message`                   | The log message text.                                                                                                                                  |
| `severity`                  | The log level: `FATAL`, `ERROR`, `WARN`, `INFO`, `DEBUG`, `TRACE`, or `METRIC`.                                                                        |
| `flowName`                  | The name of the flow that produced the log (when applicable).                                                                                          |
| `instanceId`                | The ID of the instance that produced the log.                                                                                                          |
| `instanceName`              | The name of the instance that produced the log.                                                                                                        |
| `instanceType`              | `INTEGRATION` for a standard instance, or `WORKFLOW` for an embedded customer workflow.                                                                |
| `customerName`              | The name of the customer associated with the instance.                                                                                                 |
| `integrationName`           | The name of the integration associated with the instance.                                                                                              |
| `executionResultId`         | The ID of the [execution result](https://prismatic.io/docs/api/common-queries/fetching-step-results.md) this log was produced during, when applicable. |
| `requiredConfigVariableKey` | The key of the config variable this log is associated with, for connection and data source logs.                                                       |

## Filtering logs[​](#filtering-logs "Direct link to Filtering logs")

Narrow your results by combining the `events` query arguments:

* **By time range** - pass both `timestampGte` and `timestampLte` as ISO 8601 timestamps to query a specific window.
* **By log type and severity** - use `filterGroups` to filter on `logType` (for example, `EXECUTION` vs. `CONNECTION`) or `severity` (for example, `ERROR` vs. `INFO`).
* **By flow, instance, customer, or integration** - use `filterGroups` to filter on fields like `instanceId` or `flowName`.

## Paginating through results[​](#paginating-through-results "Direct link to Paginating through results")

Like other Prismatic queries, the `events` query returns up to 100 nodes per page. If `pageInfo.hasNextPage` is `true`, use the `pageInfo.endCursor` value as the `after` argument on your next request to fetch the next page. For more information, see [Pagination](https://prismatic.io/docs/api/pagination.md).

## Fetching logs with Node.js[​](#fetching-logs-with-nodejs "Direct link to Fetching logs with Node.js")

The example below fetches all log events in a time window, paging through results until every page has been processed. It prints each log entry to the console.

Fetching Logs with Node.js

```js
const PRISMATIC_URL =
  process.env.PRISMATIC_URL || "https://app.prismatic.io/api";
const PRISMATIC_API_KEY = process.env.PRISMATIC_API_KEY;

const query = `query FetchLogs($timestampGte: DateTime!, $timestampLte: DateTime!, $after: String) {
  events(
    typeIn: [LOG_EVENT]
    orderBy: { field: TIMESTAMP, direction: DESC }
    timestampGte: $timestampGte
    timestampLte: $timestampLte
    after: $after
  ) {
    nodes {
      id
      timestamp
      ... on LogEvent {
        logType
        message
        flowName
        severity
        instanceName
        customerName
        integrationName
        executionResultId
      }
    }
    pageInfo {
      hasNextPage
      endCursor
    }
  }
}`;

async function fetchLogs(timestampGte, timestampLte) {
  let after = null;
  const logs = [];

  do {
    const response = await fetch(PRISMATIC_URL, {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
        Authorization: `Bearer ${PRISMATIC_API_KEY}`,
      },
      body: JSON.stringify({
        query,
        variables: { timestampGte, timestampLte, after },
      }),
    });

    const { data, errors } = await response.json();
    if (errors) {
      throw new Error(JSON.stringify(errors));
    }

    logs.push(...data.events.nodes);
    after = data.events.pageInfo.hasNextPage
      ? data.events.pageInfo.endCursor
      : null;
  } while (after);

  return logs;
}

async function main() {
  const logs = await fetchLogs(
    "2026-04-22T00:00:00+00:00",
    "2026-04-22T23:59:59+00:00",
  );

  for (const log of logs) {
    console.log(
      `[${log.timestamp}] ${log.severity} ${log.logType} - ${log.message}`,
    );
  }
}

main();

```
