Skip to main content

Get Moxie Promotion Details On A Certain Cast Hash

In this tutorial, you will learn how to get Moxie Earn promotion details promoted on a certain cast hash 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 Moxie Earn promotion details promoted on a certain cast hash, you can use the following query:

query Query($status: [PromotionStatus!], $castHash: String) {
GetMoxiePromotions(
input: { filter: { status: $status, castHash: $castHash } }
) {
promotions {
actualBudget
audienceReach
avgFarScore
castHash
castURL
castedByFid
createdAt
initialBudget
promoterFid
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!], $castHash: String) {
GetMoxiePromotions(
input: { filter: { status: $status, castHash: $castHash } }
) {
promotions {
actualBudget
audienceReach
avgFarScore
castHash
castURL
castedByFid
createdAt
initialBudget
promoterFid
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 the cast hash here
"castHash": "0x",
"status": ["ACTIVE", "INACTIVE", "CREATED"],
}

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",
"promoterFid": "3",
"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": "CREATED",
"updatedAt": "2024-11-04 12:11:51.000"
}
]
}
}
}

Congrats! 🥳🎉 You've just successfully fetch all active Moxie Earn promotions promoted on a certain cast hash!

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.