> ## Documentation Index
> Fetch the complete documentation index at: https://docs.neynar.com/llms.txt
> Use this file to discover all available pages before exploring further.

# How to fetch notifications for a Farcaster user

> Fetch all notifications for a given fid

<Info>
  ### API endpoint

  This tutorial uses the [GET v2/notifications](/reference/fetch-all-notifications) endpoint
</Info>

Show follow, like, recast, reply, quote and mention notifications for a given user.

<Frame>
  <img src="https://mintcdn.com/neynar/4PNY113y9N9T-r9z/images/docs/ab5bf6b-image.png?fit=max&auto=format&n=4PNY113y9N9T-r9z&q=85&s=9bb961fe846bc155ff68c6d1117a9b79" alt="notifications" width="2502" height="2048" data-path="images/docs/ab5bf6b-image.png" />
</Frame>

## Get notifications for a given user `fid`

In this example, we will try to create a notifications page for the given user.

### Prerequisites

* Install [Node.js](https://nodejs.org/en/download/package-manager)
* Optional: Install [Yarn](https://classic.yarnpkg.com/lang/en/docs/install/#mac-stable) (Alternatively, npm can be used)

### Project Setup

**Initialize Project Directory**

<CodeGroup>
  ```bash Shell theme={"system"}
  mkdir fetch-notifications-for-a-user
  cd fetch-notifications-for-a-user
  ```
</CodeGroup>

**Install Neynar SDK along with typescript**

Install using npm

<CodeGroup>
  ```bash Shell theme={"system"}
  npm i @neynar/nodejs-sdk
  npm i -D typescript
  ```
</CodeGroup>

// or

Install using Yarn

<CodeGroup>
  ```bash Shell theme={"system"}
  yarn add @neynar/nodejs-sdk
  yarn add -D typescript
  ```
</CodeGroup>

**Initialize typescript environment**

<CodeGroup>
  ```bash Shell theme={"system"}
  npx tsc --init
  ```
</CodeGroup>

### Implementation

Create index.ts file at root level

<CodeGroup>
  ```bash Shell theme={"system"}
  touch index.ts
  ```
</CodeGroup>

Add imports

<CodeGroup>
  ```typescript Typescript theme={"system"}
  import { NeynarAPIClient, isApiErrorResponse } from "@neynar/nodejs-sdk";
  import { AxiosError } from "axios";
  ```
</CodeGroup>

Instantiate the client

<CodeGroup>
  ```typescript Typescript theme={"system"}
  const client = new NeynarAPIClient("API_KEY");
  ```
</CodeGroup>

Call `fetchAllNotifications` function to get feed

<CodeGroup>
  ```typescript Typescript theme={"system"}
  (async () => {
    try {
      const cast =
        await client.fetchAllNotifications(194, {
          limit: 1, // change to however many notifications you want to get at once (max 50)
        });
      console.log(JSON.stringify(cast));
    } catch (error) {
      // isApiErrorResponse can be used to check for Neynar API errors
      // handle errors accordingly
      if (isApiErrorResponse(error)) {
        console.log("API Error", error.response.data);
      } else {
        console.log("Generic Error", error);
      }
    }
  })();
  ```
</CodeGroup>

### Running the project

<CodeGroup>
  ```bash Shell theme={"system"}
  npx ts-node index.ts
  ```
</CodeGroup>

### Result

#### You should now see an output like this

```json theme={"system"}
{
  "notifications": [
    {
      "object": "notification",
      "most_recent_timestamp": "2023-11-17T01:22:43.000Z",
      "type": "likes", // Can be "likes", "mentions", "replies", or "quotes"
      "cast": {
        "hash": "0x1aa36542c2dc8799dded2cde37a3c1a3840eb41f",
        "thread_hash": "2a47ce562ff5ce5916ea9095227c5fbff9618157",
        "parent_hash": "2a47ce562ff5ce5916ea9095227c5fbff9618157",
        "parent_url": null,
        "parent_author": {
          "fid": "576"
        },
        "author": {
          "object": "user",
          "fid": 194,
          "custody_address": "0xb95dc10483be18f7c69ddf78d4baafecc01c5530",
          "username": "rish",
          "display_name": "rish",
          "pfp_url": "https://res.cloudinary.com/merkle-manufactory/image/fetch/c_fill,f_png,w_256/https://lh3.googleusercontent.com/MEaRCAMdER6MKcvmlfN1-0fVxOGz6w98R8CrP_Rpzse9KZudgn95frTd0L0ZViWVklBj9fuAcJuM6tt7P-BRN0ouAR87NpzZeh2DGw",
          "profile": {
            "bio": {
              "text": "@neynar 🪐 | nf.td/rish",
              "mentioned_profiles": []
            }
          },
          "follower_count": 8313,
          "following_count": 470,
          "verifications": [
            "0x5a927ac639636e534b678e81768ca19e2c6280b7",
            "0xe9e261852ea62150eee685807df8fe3f211310a0"
          ],
          "active_status": "active"
        },
        "text": "wtf",
        "timestamp": "2023-11-17T00:56:01.000Z",
        "embeds": [],
        "reactions": {
          "likes": [
            {
              "fid": 1600,
              "fname": "yashkarthik"
            },
            {
              "fid": 576,
              "fname": "nonlinear.eth"
            },
            {
              "fid": 6546,
              "fname": "artlu.eth"
            }
          ],
          "recasts": []
        },
        "replies": {
          "count": 1
        },
        "mentioned_profiles": []
      },
      "reactions": [
        {
          "object": "likes",
          "cast": {
            "object": "cast_dehydrated",
            "hash": "0x1aa36542c2dc8799dded2cde37a3c1a3840eb41f"
          },
          "user": {
            "object": "user",
            "fid": 1600,
            "username": "yashkarthik",
            "display_name": "Yash Karthik",
            "pfp_url": "https://lh3.googleusercontent.com/W_MM3NN-i9OYxM3XPJjwpb5mkMLjJFZJjnEXsvrhiTwirSFhRjyAa3qTzV63ago6NkX9qeesi20hoK9fHdhiE-SqICH0vPcTm3Dl",
            "profile": {
              "bio": {
                "text": "I like building cool stuff on top of Ethereum, Farcaster and GPT (dm for collab)\n\nCurrently learning C and exploring low level stuff\n\nnf.td/yashkarthik"
              }
            },
            "follower_count": 585,
            "following_count": 336,
            "verifications": [
              "0x33cc45d8b0336bfa830fb512b54b02a049277403"
            ],
            "active_status": "active"
          }
        },
      ]
    }
  ],
  "next": {
    "cursor": "eyJ0aW1lc3RhbXAiOiIyMDIzLTExLTE3IDAxOjIyOjQzLjAwMDAwMDAifQ=="
  }
}
```

### Summary

You can use this to show a notification on your client! **You get all the data in one request, making it easy to display or use in your next operation.** If you want to try getting a live response, head over to our API page for [v2/feed](/reference/fetch-user-following-feed).

You can take the cursor from the output and pass it in the next request to the SDK to page to the next set of results.

<Info>
  ### Ready to start building?

  Get your subscription at [neynar.com](https://neynar.com) and reach out to us on [Slack](https://neynar.com/slack) with any questions!
</Info>
