Fetch notifications for any Farcaster user
import { NeynarAPIClient, Configuration } from "@neynar/nodejs-sdk";
// make sure to set your NEYNAR_API_KEY .env
// don't have an API key yet? get one at neynar.com
const config = new Configuration({
apiKey: process.env.NEYNAR_API_KEY,
});
const client = new NeynarAPIClient(config);
const dwrFID = 3;
const notifications = await client.fetchAllNotifications({fid:dwrFID});
console.log(notifications);
{
notifications: [
{
object: "notification",
most_recent_timestamp: "2023-11-28T11:11:11.000Z",
type: "likes",
cast: [Object ...],
reactions: [
[Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...]
]
}, {
object: "notification",
most_recent_timestamp: "2023-11-28T11:10:56.000Z",
type: "quote",
cast: [Object ...],
quotes: [
[Object ...], [Object ...]
]
}, {
object: "notification",
most_recent_timestamp: "2023-11-28T11:09:16.000Z",
type: "likes",
cast: [Object ...],
reactions: [
[Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...]
]
}, {
object: "notification",
most_recent_timestamp: "2023-11-28T11:05:59.000Z",
type: "follows",
follows: [
[Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...]
]
}, {
object: "notification",
most_recent_timestamp: "2023-11-28T10:25:51.000Z",
type: "likes",
cast: [Object ...],
reactions: [
[Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...],
[Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...]
]
}
],
next: {
cursor: "eyJ0aW1lc3RhbXAiOiIyMDIzLTExLTI4IDEwOjI1OjUxLjAwMDAwMDAifQ=="
}
}
const nextNotifications = await client.fetchAllNotifications({
fid: dwrFID,
cursor: notifications.next.cursor,
});
const mentionsAndReplies = await client.fetchAllNotifications({
fid: dwrFID,
});
console.log(mentionsAndReplies);
{
result: {
notifications: [
[Object ...], [Object ...], [Object ...], [Object ...], [Object ...]
],
next: {
cursor: "eyJ0aW1lc3RhbXAiOiIyMDIzLTExLTI4IDA3OjI5OjI4LjAwMDAwMDAifQ=="
}
}
}
const nextMentionsAndReplies = await client.fetchAllNotifications({
fid: dwrFID,
cursor: mentionsAndReplies.next.cursor,
});
console.log(nextMentionsAndReplies);
Was this page helpful?