> ## 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 Get Cast Information for Farcaster Casts

> To get all information about a cast, traditionally, you have to run a hub or get access to a hosted indexer.

<Info>
  ### API endpoint

  This tutorial uses the [GET v2/cast](/reference/fetch-embedded-url-metadata) endpoint
</Info>

You have to fetch the raw cast data, mentioned profiles, reactions, profile of the author, etc. and stitch it back into the final cast object before you can render it or use the data in a subsequent operation. Thankfully, Neynar's SDK and APIs make this much simpler!

<Frame>
  <img src="https://mintcdn.com/neynar/V7Un5QUQSGJFAZfS/images/docs/ea58d37-image.png?fit=max&auto=format&n=V7Un5QUQSGJFAZfS&q=85&s=e1c923dfe653abf7ae555f9f28b198f7" alt="cast information" width="1238" height="1296" data-path="images/docs/ea58d37-image.png" />
</Frame>

## Fetch cast information easily with Neynar SDK

#### Ensure you have the right environment setup

Make sure to have node.js, typescript (ts) and yarn installed on your machine

* Install [node.js and npm](https://nodejs.org/en/download/)
* Install [yarn](https://classic.yarnpkg.com/lang/en/docs/install/#mac-stable)
* Install [ts-node](https://www.npmjs.com/package/ts-node#installation) globally

#### Create a new typescript file with the right imports

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

  import {
    CastParamType,
  } from "@neynar/nodejs-sdk/build/neynar-api/neynar-v2-api";
  ```
</CodeGroup>

#### Initialize the client

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

#### Call `lookUpCastByHashOrUrl` function to get cast data based on a url

<CodeGroup>
  ```typescript index.ts theme={"system"}
  (async () => {
    try {
      const cast = await client.lookUpCastByHashOrUrl(
        'https://warpcast.com/rish/0x9288c1',
        CastParamType.Url
      );
      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>

*You can change the `CastParamType.Url` to `CastParamType.Hash` use a hash (e.g. 0x123...abc) instead to fetch cast data if you so want.*

#### Run your new .ts file

* Navigate to the right folder in your terminal e.g. `cd ./test-sdk`
* Run script by typing `yarn start` into the terminal

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

<CodeGroup>
  ```json JSON theme={"system"}
  {
      "cast": {
          "hash":"0x9288c1e862aa72bd69d0e383a28b9a76b63cbdb4",
          "thread_hash":"0x9288c1e862aa72bd69d0e383a28b9a76b63cbdb4",
          "parent_hash":null,
          "parent_url":"chain://eip155:7777777/erc721:0x4f86113fc3e9783cf3ec9a552cbb566716a57628",
          "parent_author": {
                  "fid":null
              },
          "author": {
              "object":"user",
              "fid":194,
              "custody_address":"0xb43a7cc909d842721c288ff90b03e511a78a4a8d",
              "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":8253,
              "following_count":468,
              "verifications": [
                  "0x5a927ac639636e534b678e81768ca19e2c6280b7",
                  "0xe9e261852ea62150eee685807df8fe3f211310a0"
              ],
              "active_status":"active"
          },
          "app": {
              "object": "user_dehydrated",
              "fid": 9152,
              "username": "warpcast",
              "display_name": "Warpcast",
              "pfp_url": "https://i.imgur.com/3d6fFAI.png"
          },
          "text":".@fun built out hatecast.xyz based on a random conversation we had about app ideas for Farcaster.\n\nThere are many things we'd love to build at @neynar if we had the time but spoiler alert: we don't. So would love to see others build these! \nhttps://paragraph.xyz/@neynar/farcaster-ideas \n\n🪐",
          "timestamp":"2023-09-13T22:10:22.000Z",
          "embeds": [
              {
                  "url":"https://paragraph.xyz/@neynar/farcaster-ideas"
                  }
              ],
          "reactions": {
              "likes": [
                  {
                      "fid":1285,
                      "fname":"0xbenersing.eth"
                  },
                  {
                      "fid":19315,
                      "fname":"sonofsun"
                  }
              ],
              "recasts": [
                  {
                      "fid":19036,
                      "fname":"geohookah"
                  },
                  {
                      "fid":13313,
                      "fname":"008"
                  }
              ]
          },
          "replies": {
              "count":10
          },
          "mentioned_profiles": [
              {
                  "object":"user",
                  "fid":5620,
                  "custody_address":"0xbee82d68f49ee2aa8408f8111db64d92e4d61971",
                  "username":"fun",
                  "display_name":"welter.eth",
                  "pfp_url":"https://i.imgur.com/LE5osyF.jpg",
                  "profile": {
                      "bio": {
                          "text":"building apps like FarcasterUserStats.com",
                          "mentioned_profiles":[]
                      }
                  },
                  "follower_count":1522,
                  "following_count":207,
                  "verifications": [
                      "0x02ac33835070d0c90bef87c273514e67aea36ef8"
                  ],
                  "active_status":"active"
              }
          ]
      }
  }
  ```
</CodeGroup>

**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/cast](/reference/fetch-embedded-url-metadata).

<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>
