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
- 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 all active Moxie Earn promotions promoted by a certain Farcaster user, you can use the following query:
- Query
- Variable
- Response
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
}
}
}
{
// input an existing Moxie Earn promotion ID here
"promoterFid": "602",
"status": ["ACTIVE"],
}
{
"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"
}
]
}
}
}
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!], $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);
}
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!], $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:
- 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",
"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.