Query examples
This page provides additional examples of various queries for Alerts API

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 guide.
1
query findAlerts {
2
alerts(
3
where: {
4
company: {
5
id: { in: [334, 1842] }
6
},
7
publishedAt: {
8
gte: "2021-01-01",
9
lte: "2021-02-01"
10
}
11
}
12
) {
13
id
14
text
15
title
16
company {
17
displayName
18
}
19
}
20
}
Copied!

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 for more details on how to work with paginated queries.
1
query findAlerts($after: ID!, $where: AlertBoolExpression!) {
2
alerts(
3
first: 100,
4
after: $after,
5
where: $where,
6
) {
7
text
8
title
9
class {
10
label
11
}
12
}
13
}
Copied!
where argument could have the following shape:
1
{
2
"publishedAt": { "gt": "2021-01-01" }
3
}
Copied!

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.
1
query findAlerts {
2
alerts {
3
id
4
dataset
5
polarity
6
payload
7
class {
8
code
9
label
10
}
11
resource {
12
id
13
type
14
}
15
title
16
text
17
source
18
value
19
variable
20
company {
21
id
22
displayName
23
homepage
24
}
25
period
26
publishedAt
27
occuredAt
28
}
29
}
Copied!

Fetch all available Commodity Alerts since the given date

Please, note that particular dataset and class availability depends on your contractual agreement with Craft. Reach out to [email protected] for additional details.
This query filters alerts by the dataset and publishedAt fields.
1
query FetchCommodityAlerts($after: ID!, $where: AlertBoolExpression!) {
2
alerts(
3
first: 100,
4
after: $after,
5
where: $where,
6
) {
7
text
8
polarity
9
payload
10
resource {
11
id
12
type
13
}
14
}
15
}
Copied!
where object could have the following shape:
1
{
2
"publishedAt": { "gt": "2022-01-01" },
3
"dataset": { "eq": "news_commodities" }
4
}
Copied!
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.
You may also apply additional filters and sorting order 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.
1
query FetchAlertsByPolarity {
2
positiveAlerts: alerts(
3
where: {
4
polarity: {
5
gt: 0
6
}
7
}
8
) {
9
id
10
polarity
11
text
12
}
13
neutralAlerts: alerts(
14
where: {
15
polarity: {
16
eq: 0
17
}
18
}
19
) {
20
id
21
polarity
22
text
23
}
24
negativeAlerts: alerts(
25
where: {
26
polarity: {
27
lt: 0
28
}
29
}
30
) {
31
id
32
polarity
33
text
34
}
35
}
Copied!
In addition to gt, lt and eq, you may use other IntComparisonExpression operators as needed.
Copy link
Contents