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
- 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 get Moxie Earn promotion details promoted on a certain cast hash, you can use the following query:
- Query
- Variable
- Response
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
}
}
}
{
// input the cast hash here
"castHash": "0x",
"status": ["ACTIVE", "INACTIVE", "CREATED"],
}
{
"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"
}
]
}
}
}
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 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);
}
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 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:
- TypeScript
- JavaScript
ts-node index.ts
node index.js
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 Moxie Official Warpcast channel and ask your questions there.
Our team is always ready to help you with any questions you may have.