Roblox group sales webhook

I basically want to send a webhook to my Discord server whenever someone purchases an item.

https://economy.roblox.com/v2/groups/{GROUP_ID}/transactions?limit=25&sortOrder=Asc&transactionType=Sale&cursor={CURSOR}

I was browsing and came across this ^
How would I make it work by using that url?

1 Like

Just make it so that when an update to the group transactions response is detected, find the change and send the transaction info of the purchase to the webhook. Here’s an example program:

const fetch = require('node-fetch');
const { WebhookClient, MessageEmbed } = require('discord.js');

const ROBLOX_API_ENDPOINT = 'https://economy.roblox.com/v2/groups/123/transactions?limit=25&sortOrder=Asc&transactionType=Sale';
const DISCORD_WEBHOOK_URL = 'https://discord.com/webhooks/123';
let lastTransactionIdHash = null;

const webhookClient = new WebhookClient({ url: DISCORD_WEBHOOK_URL });

async function fetchTransactions() {
  try {
    const response = await fetch(ROBLOX_API_ENDPOINT);
    const data = await response.json();

    if (!data || !data.data || data.data.length === 0) {
      console.log('empty');
      return;
    }

    const latestTransaction = data.data[0];
    if (latestTransaction.idHash !== lastTransactionIdHash) {
      lastTransactionIdHash = latestTransaction.idHash;
      console.log('new transaction: ', latestTransaction);

      sendTransactionToDiscord(latestTransaction);
    } else {
      console.log('no new transactions');
    }
  } catch (error) {
    console.error('other error:', error);
  }
}

function sendTransactionToDiscord(transaction) {
  const embed = new MessageEmbed()
    .setTitle('Purchase')
    .addField('ID', transaction.id)
    .addField('Date', transaction.created)
    .addField('Buyer', transaction.agent.name)
    .addField('Name', transaction.details.name)
    .addField('Price', transaction.currency.amount);

  webhookClient.send({
    embeds: [embed],
  }).then(() => {
    console.log('successfully sent data to Discord');
  }).catch((error) => {
    console.error('discord error:', error);
  });
}

// fetch and process every 60 seconds
setInterval(fetchTransactions, 60000);

fetchTransactions();

I’m not very familiar with the Discord API so it might not work as intended but that’s the general idea.

2 Likes