Create A Personalized Earned Feeds For A Certain User
In this tutorial, you will learn how to create a personalized earned feeds for a certain Farcaster user by calling the Moxie Partner API.
Pre-requisites
- Install dependencies
graphql
andgraphql-request
to your project :
- npm
- yarn
- pnpm
- bun
npm install graphql graphql-request
yarn add graphql graphql-request
pnpm add graphql graphql-request
bun install graphql graphql graphql-request
- Your will need a special API key to access to the Moxie Partner API. To request access, please fill in this form here.
Step 1: Add The API Query To Your Code
To create a personalized earned feeds for a certain Farcaster user, you can use the following query:
- Query
- Variable
- Response
query ($earnerFid: String!, $targetAudienceStatus: [TargetAudienceStatus]) {
FetchEligiblePromotions(input: {
earnerFid: $earnerFid,
targetAudienceStatus: $targetAudienceStatus,
}) {
earnerFid
promotions {
castHash
castURL
castedByFid
createdAt
promoterFid
rewardBoost
status
updatedAt
promotionId
targetAudienceStatus
}
}
}
{
// specify the FID of the Farcaster user
"earnerFid": "602",
"status": "ACTIVE",
}
{
"data": {
"FetchEligiblePromotions": {
"earnerFid": "602",
"promotions": [
{
"castHash": "0x69e8bb6c0827b865434c84a36cf41a024b5d1de0",
"castURL": "https://warpcast.com/eduardmsmr/0x69e8bb6c",
"castedByFid": "290249",
"createdAt": "2024-11-05 03:27:55.000",
"promoterFid": "8408",
"rewardBoost": 5,
"status": "ACTIVE",
"updatedAt": "2024-11-05 03:30:28.000",
"promotionId": "a1bb3d5a-3757-4be3-baf5-c3755ef99542",
"targetAudienceStatus": "ACTIVE"
},
// Other eligible Moxie earn promotions for the user
]
}
}
}
graphql-request
library:- TypeScript
- JavaScript
index.ts
import { gql, GraphQLClient } from "graphql-request";
import { config } from "dotenv";
config();
const graphQLClient = new GraphQLClient(
"https://api.moxie.xyz/promotion/graphql"
);
const query = gql`
query ($earnerFid: String!, $targetAudienceStatus: [TargetAudienceStatus]) {
FetchEligiblePromotions(input: {
earnerFid: $earnerFid,
targetAudienceStatus: $targetAudienceStatus,
}) {
earnerFid
promotions {
castHash
castURL
castedByFid
createdAt
promoterFid
rewardBoost
status
updatedAt
promotionId
targetAudienceStatus
}
}
}
`;
const variable = {
// specify the FID of the Farcaster user
"earnerFid": "602",
"status": "ACTIVE",
}
const headers = {
// Add Airstack API key here
"x-airstack-promotion": process.env.AIRSTACK_API_KEY as string,
}
try {
const data = await graphQLClient.request(query, variable, headers);
console.log(data);
} catch (e) {
throw new Error(e);
}
index.js
const { gql, GraphQLClient } = require("graphql-request");
const { config } = require("dotenv");
config();
const graphQLClient = new GraphQLClient(
"https://api.moxie.xyz/promotion/graphql"
);
const query = gql`
query ($earnerFid: String!, $targetAudienceStatus: [TargetAudienceStatus]) {
FetchEligiblePromotions(input: {
earnerFid: $earnerFid,
targetAudienceStatus: $targetAudienceStatus,
}) {
earnerFid
promotions {
castHash
castURL
castedByFid
createdAt
promoterFid
rewardBoost
status
updatedAt
promotionId
targetAudienceStatus
}
}
}
`;
const variable = {
// specify the FID of the Farcaster user
"earnerFid": "602",
"status": "ACTIVE",
}
const headers = {
// Add Airstack API key here
"x-airstack-promotion": process.env.AIRSTACK_API_KEY as string,
}
try {
const data = await graphQLClient.request(query, variable, headers);
console.log(data);
} catch (e) {
throw new Error(e);
}
Step 2: Execute Your Code
Once you have your code ready, you can execute it by running the following command:
- TypeScript
- JavaScript
ts-node index.ts
node index.js
If it runs successfully, you should see the data returned in the terminal:
{
"data": {
"FetchEligiblePromotions": {
"earnerFid": "602",
"promotions": [
{
"castHash": "0x69e8bb6c0827b865434c84a36cf41a024b5d1de0",
"castURL": "https://warpcast.com/eduardmsmr/0x69e8bb6c",
"castedByFid": "290249",
"createdAt": "2024-11-05 03:27:55.000",
"promoterFid": "8408",
"rewardBoost": 5,
"status": "ACTIVE",
"updatedAt": "2024-11-05 03:30:28.000",
"promotionId": "a1bb3d5a-3757-4be3-baf5-c3755ef99542",
"targetAudienceStatus": "ACTIVE"
}
// Other eligible Moxie earn promotions for the user
]
}
}
}
Congrats! 🥳🎉 You've just successfully create a personalized earned feeds for a certain Farcaster user!
Developer Support
If you have any questions or need help with other use cases, feel free to join the Moxie Official Warpcast channel and ask your questions there.
Our team is always ready to help you with any questions you may have.