Skip to main content

Get All Active Moxie Promotions Promoted By A User

In this tutorial, you will learn how to get all active Moxie Earn promotions promoted by a certain Farcaster user by calling the Moxie Partner API.

Pre-requisites

  1. Install dependencies graphqlandgraphql-request to your project :
npm install graphql graphql-request
  1. 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 get all active Moxie Earn promotions promoted by a certain Farcaster user, you can use the following query:

query Query($status: [PromotionStatus!], $promoterFid: String) {
GetMoxiePromotions(input: {
filter: {
status: $status,
promoterFid: $promoterFid
}
}) {
promotions {
actualBudget
audienceReach
avgFarScore
castHash
castURL
castedByFid
createdAt
initialBudget
promotionId
promotionRuleOperatorType
promotionRules {
channelFollowerRule {
operatorType
value
}
channelMemberRule {
operatorType
value
}
farRankRule {
operatorType
value
}
farScoreRule {
operatorType
value
}
followedByRule {
operatorType
value
}
ruleType
}
remainingBudget
rewardBoost
status
updatedAt
}
}
}
With this GraphQL query, you can add it to your source code and call the API with the graphql-request library:
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 Query($status: [PromotionStatus!], $promoterFid: String) {
GetMoxiePromotions(input: {
filter: {
status: $status,
promoterFid: $promoterFid
}
}) {
promotions {
actualBudget
audienceReach
avgFarScore
castHash
castURL
castedByFid
createdAt
initialBudget
promotionId
promotionRuleOperatorType
promotionRules {
channelFollowerRule {
operatorType
value
}
channelMemberRule {
operatorType
value
}
farRankRule {
operatorType
value
}
farScoreRule {
operatorType
value
}
followedByRule {
operatorType
value
}
ruleType
}
remainingBudget
rewardBoost
status
updatedAt
}
}
}
`;

const variable = {
// input an existing Moxie Earn promotion ID here
"promoterFid": "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:

ts-node index.ts

If it runs successfully, you should see the data returned in the terminal:

{
"data": {
"GetMoxiePromotions": {
"promotions": [
{
"actualBudget": "0",
"audienceReach": 0,
"avgFarScore": 0,
"castHash": "0x",
"castURL": "https://test.xyz",
"castedByFid": "602",
"createdAt": "2024-11-04 12:11:51.000",
"initialBudget": "20",
"promotionId": "b1ee5208-f127-47a5-b483-f125c9a8495f",
"promotionRuleOperatorType": "AND",
"promotionRules": [
{
"channelFollowerRule": null,
"channelMemberRule": null,
"farRankRule": null,
"farScoreRule": null,
"followedByRule": {
"operatorType": "TOTAL_GREATER_THAN",
"value": ["3"]
},
"ruleType": "FOLLOWED_BY"
}
],
"remainingBudget": "0",
"rewardBoost": 2,
"status": "ACTIVE",
"updatedAt": "2024-11-04 12:11:51.000"
}
]
}
}
}

Congrats! 🥳🎉 You've just successfully fetch all active Moxie Earn promotions promoted by a certain Farcaster user!

Developer Support

If you have any questions or need help with other use cases, feel free to join the /airstack Warpcast channel and ask your questions there.

Our team is always ready to help you with any questions you may have.