# Query examples

#### Find Alerts for a set of Companies between certain dates

We're using `where` filter with multiple fields to find all of the Alerts from January 2021 for two given companies. You may find more details about filters in Alerts API in the [Filtering and sorting](/alerts-api/alerts-api-queries/filtering-and-sorting.md) guide.

```graphql
query findAlerts {
  alerts(
    where: {
      company: {
        id: { in: [334, 1842] }
      },
      publishedAt: {
        gte: "2021-01-01",
        lte: "2021-02-01"
      }
    }
  ) {
    id
    text
    title
    company {
      displayName
    }
  }
}
```

#### Find all Alerts from a certain date till now

Such a query might potentially return more entities than allowed per page. Please see the [Alerts API pagination guide](/alerts-api/alerts-api-queries/pagination.md) for more details on how to work with paginated queries.&#x20;

```graphql
query findAlerts($after: ID!, $where: AlertBoolExpression!) {
  alerts(
    first: 100,
    after: $after,
    where: $where,
  ) {
    text
    title
    class {
      label
    }
  }
}
```

`where` argument could have the following shape:

```javascript
{
  "publishedAt": { "gt": "2021-01-01" }
}
```

#### Fetch all available Alert fields

This query demonstrates all of the fields currently available on the Alert node. You may find the full type definitions available in the [Alerts API Reference](/alerts-api/alerts-api-reference/alert-object.md).

```graphql
query findAlerts {
  alerts {
    id
    dataset
    polarity
    payload
    class {
      code
      label
    }
    resource {
      id
      type
    }
    title
    text
    source
    value
    variable
    company {
      id
      displayName
      homepage
    }
    period
    publishedAt
    occuredAt
  }
}
```

#### Fetch all available Commodity Alerts since the given date

{% hint style="info" %}
Please, note that particular dataset and class availability depends on your contractual agreement with Craft. Reach out to <sales@craft.co> for additional details.
{% endhint %}

This query filters alerts by the `dataset` and `publishedAt` fields.

```graphql
query FetchCommodityAlerts($after: ID!, $where: AlertBoolExpression!) {
  alerts(
    first: 100,
    after: $after,
    where: $where,
  ) {
    text
    polarity
    payload
    resource {
      id
      type
    }
  }
}
```

`where` object could have the following shape:

```javascript
{
  "publishedAt": { "gt": "2022-01-01" },
  "dataset": { "eq": "news_commodities" }
}
```

The query may return more than 100 records for a single request if there were more Alerts published during the given period of time. In order to fetch all of the records, please refer to the [Alerts Pagination Guide](/alerts-api/alerts-api-queries/pagination.md).

You may also apply additional [filters and sorting order](/alerts-api/alerts-api-queries/filtering-and-sorting.md) if needed.

#### Filter Alerts by Polarity

This query shows how to find Alerts that have certain intent or sentiment (positive, negative or neutral) associated with them.

`polarity` field is an `Int` where all the values below `0` represent a negative sentiment and all values above - represent a positive one.&#x20;

```graphql
query FetchAlertsByPolarity {
  positiveAlerts: alerts(
    where: {
      polarity: {
        gt: 0
      }
    }
  ) {
    id
    polarity
    text
  }
  neutralAlerts: alerts(
    where: {
      polarity: {
        eq: 0
      }
    }
  ) {
    id
    polarity
    text
  }
  negativeAlerts: alerts(
    where: {
      polarity: {
        lt: 0
      }
    }
  ) {
    id
    polarity
    text
  }
}
```

In addition to `gt`, `lt` and `eq`, you may use other [IntComparisonExpression](/alerts-api/alerts-api-reference/filter-object.md) operators as needed.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.craft.co/alerts-api/query-examples.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
