Neynar Documentation
API endpoint
This tutorial uses the GET v2/feed endpoint
Imagine you want to create a custom list of users in your app and show a feed of casts based on users in the list, similar to Twitter lists.
Create a feed given a list of users
In this example, we will try to feed for fids 1, 2 and 3. If you know someone’s username, you can find their fid from our user endpoint.
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
- Install yarn
- Install ts-node globally
Create a new typescript file with the right imports
import { NeynarAPIClient, isApiErrorResponse } from "@neynar/nodejs-sdk";
import { AxiosError } from "axios";
import {
FeedType, FilterType,
} from "@neynar/nodejs-sdk/build/neynar-api/neynar-v2-api";
Initialize the client
const client = new NeynarAPIClient("API_KEY");
Call fetchFeedPage function to get feed
(async () => {
try {
const cast =
await client.fetchFeedPage(FeedType.Filter, {
filterType: FilterType.Fids,
fids: "1,2,3",
limit: 1, // change to however many casts you want to fetch at once (max 100)
withRecasts: true,
});
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);
}
}
})();
Run your new .ts file
- Navigate to the right folder in your terminal e.g.
cd ./test-sdk - Run script by typing
yarn startinto the terminal
You should now see an output like this
{
"casts": [
{
"hash": "0x46db48a011698758bfb9b1f77c07596249e277ef",
"thread_hash": "0x46db48a011698758bfb9b1f77c07596249e277ef",
"parent_hash": null,
"parent_url": "chain://eip155:7777777/erc721:0xe96c21b136a477a6a97332694f0caae9fbb05634",
"parent_author": {
"fid": null
},
"author": {
"object": "user",
"fid": 3647,
"custody_address": "0x54faa8c0c270093fcd0f0c4b29ace4d5426113b7",
"username": "iamnick.eth",
"display_name": "Nick Smith",
"pfp_url": "https://i.seadn.io/gcs/files/8583feea8a3465788d84367a92d80512.png?w=500&auto=format",
"profile": {
"bio": {
"text": "Building withfam.xyz Prev. Co-founder @ talisman.xyz ✴︎ Member @ FWB, Builder DAO, The Park ✷",
"mentioned_profiles": []
}
},
"follower_count": 482,
"following_count": 149,
"verifications": [
"0x0f9b1b68f848cb65f532bc12825357201726d3d2"
],
"active_status": "active"
},
"text": "https://x.com/iamnickdoteth/status/1724238126884024629?s=20\n\nBoiler Room, but make it onchain\n\nwe're forming a squad. HMU if you're interested",
"timestamp": "2023-11-17T01:22:25.000Z",
"embeds": [
{
"url": "https://x.com/iamnickdoteth/status/1724238126884024629?s=20"
}
],
"reactions": {
"likes": [
{
"fid": 191213,
"fname": "stringtheory69"
},
{
"fid": 13870,
"fname": "0xsatori.eth"
},
{
"fid": 8,
"fname": "jacob"
},
{
"fid": 195091,
"fname": "greyseymour"
},
{
"fid": 7715,
"fname": "royalaid"
},
{
"fid": 1407,
"fname": "zinger"
},
{
"fid": 3115,
"fname": "ghostlinkz"
},
{
"fid": 2,
"fname": "varunsrin.eth"
}
],
"recasts": [
{
"fid": 191213,
"fname": "stringtheory69"
},
{
"fid": 7715,
"fname": "royalaid"
},
{
"fid": 2,
"fname": "varunsrin.eth"
}
]
},
"replies": {
"count": 3
},
"mentioned_profiles": []
}
],
"next": {
"cursor": "eyJ0aW1lc3RhbXAiOiIyMDIzLTExLTE3IDAxOjIyOjI1LjAwMDAwMDAifQ=="
}
}
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.