Links
💻

Pagination

V1 APIs

Paginated APIs will return a pagination token along with the result. The pagination token can be passed into your next request to continue the query. All items have been returned when the pagination token is empty.
The following code example queries for all MagicEden events:
const url = 'https://api.helius.xyz/v1/nft-events?api-key=<your_key_here>';
const getAllNftEvents = async () => {
const events = [];
let paginationToken;
while (true) {
const { data } = await axios.post(url, {
query: {
sources: ["MAGIC_EDEN"]
},
options: {
limit: 100,
paginationToken: paginationToken,
},
});
console.log(`Got batch of ${data.result.length} events!`);
events.push(...data.result);
if (data.paginationToken) {
paginationToken = data.paginationToken;
console.log(`Proceeding to next page with token ${paginationToken}.`);
} else {
console.log('Finished getting all events.');
break;
}
}
console.log(`Got ${events.length} events in total!`);
return events;
};
getAllNftEvents();

V0 APIs

By default, the API will return roughly 100 items or less. You will need to paginate the data in order to continue processing data for a given address. Pagination is performed by passing in the oldest transaction from the last request into the next request. This can be done with the before query parameter. See below for an example:
pagination.js
const axios = require('axios');
const apiURL = 'https://api.helius.xyz/v0/addresses';
const address = 'M2mx93ekt1fmXSVkTrUL9xVFHkmME8HTUi5Cyc5aF7K'; // Magic Eden
const resource = 'transactions';
const options = '?api-key=<your api key>';
const getLargeAmountOfTransactions = async (desiredCount) => {
let page = 1;
let oldestTransaction = '';
let transactions = [];
while (transactions.length <= desiredCount) {
const url = `${apiURL}/${address}/${resource}${options}&before=${oldestTransaction}`;
const { data } = await axios.get(url);
if (data.length === 0) {
// Exhausted all transactions for the given address
return transactions;
}
console.log(`Got ${data.length} transactions from page ${page}!`);
// API data is already sorted in descending order
oldestTransaction = data[data.length - 1].signature;
transactions.push(...data);
page += 1;
}
console.log(`Got ${transactions.length} total transactions!`);
return transactions;
};
getLargeAmountOfTransactions(200);