Send 3rd Party Rewards Data
If you have an app, you can setup custom Everyday Rewards for your users so that they can earn Moxie rewards by using your app based on their respective usages. If you want to enable this in your app/project, you can contact Alex for discussion.
In order to distribute the rewards, it is required for you to track user's usage on your app and send it to us.
In this tutorial, you will learn, as a vendor, how to use the Webhook 3rd Party Rewards REST API to fetch the clearing price of a certain auction in Node.js.
Pre-requisites
Before following the tutorial, make sure that your machine fulfills the following requirements:
- Install dependency
node-fetch
to your project:
- npm
- yarn
- pnpm
- bun
npm install node-fetch
yarn add node-fetch
pnpm add node-fetch
bun install graphql node-fetch
- Your will need a Partner ID & a special API key to access to the Webhook 3rd Party Rewards REST API. This will be given to you once you're onboarded as a vendor.
Step 1: Add REST API Call To The Code
You can easily call the Webhook 3rd Party Rewards REST API by sending a POST request providing the partnerId
assigned to you and add the event usage details to the request body by the following code snippet with node-fetch
:
Keep in mind that the eventId
sent to the webhook should be unique and only be sent once. If you send the same eventId
more than once, the API will revert and the usage data will not be registered on Moxie for your user's to get rewarded.
It is highly recommended that you send the usage data once the event has ended.
- TypeScript
- JavaScript
import fetch from "node-fetch";
const options = {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer <YOUR_AIRSTACK_API_KEY>",
},
body: JSON.stringify({
// unique event ID
eventId: "1",
// the host's FID
hostFid: 3,
// the start timstamp of the event
eventStartTimestamp: "2024-09-11T04:04:51.901Z",
// the end timstamp of the event
eventEndTimestamp: "2024-09-11T04:25:51.901Z",
attendees: [
{
// the attendee's FID
attendeeFid: 61,
// the duration of the attendance in seconds
attendanceDuration: 100,
},
{
attendeeFid: 21,
attendanceDuration: 1200,
},
// Other attendees
],
}),
};
// The Partner ID assigned for each vendor
const partnerId = "YOUR_PARTNER_ID";
fetch(`https://rewards.moxie.xyz/partners/${partnerId}/events`, options)
.then((response) => response.json())
.then((response) => console.log(response))
.catch((err) => console.error(err));
const fetch = require("node-fetch");
const options = {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer <YOUR_AIRSTACK_API_KEY>",
},
body: JSON.stringify({
// unique event ID
eventId: "1",
// the host's FID
hostFid: 3,
// the start timstamp of the event
eventStartTimestamp: "2024-09-11T04:04:51.901Z",
// the end timstamp of the event
eventEndTimestamp: "2024-09-11T04:25:51.901Z",
attendees: [
{
// the attendee's FID
attendeeFid: 61,
// the duration of the attendance in seconds
attendanceDuration: 100,
},
{
attendeeFid: 21,
attendanceDuration: 1200,
},
// Other attendees
],
}),
};
// The Partner ID assigned for each vendor
const partnerId = "YOUR_PARTNER_ID";
fetch(`https://rewards.moxie.xyz/partners/${partnerId}/events`, options)
.then((response) => response.json())
.then((response) => console.log(response))
.catch((err) => console.error(err));
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:
{
"requestId": "62a6ed27-61de-446e-b222-0f09dd60bb8a",
"success": true
}
If success
is true
, you have successfully sent your usage data to Moxie for processing. For your users, they should be able to claim their rewards in the Frames as part of the Everyday Rewards.
Congrats! 🥳🎉 You've just successfully sent 3rd party rewards data to Moxie!
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.