Getting top 10 from an ODS with js?

I am using node.js and I am trying to use roblox’s OrderedDataStore API to get the top 10 players in my OrderedDataStore. I have been trying for weeks and have searched over the internet but I can’t find how to do this. If you know, please help me!

1 Like

I found an official tutorial on how to do so, it’s just in Python:

https://create.roblox.com/docs/cloud/open-cloud/usage-data-stores#external-persistent-leaderboard

I found that a while ago, couldn’t figure out how to convert it to js.

I converted it for you.

ordered_data_stores.js

const axios = require('axios');

class DataStores {
    constructor(configFile) {
        const config = require(configFile);
        this._config = config;
    }

    _H() {
        return { 'x-api-key': this._config.api_key, 'Content-Type': 'application/json' };
    }

    _get_url(pathFormat) {
        return `${this._config.base_url}/${pathFormat.replace('{0}', this._config.universe_id)}`;
    }

    list(datastore, scope, pageSize = 10, orderBy = "", filter = "", exclusiveStartKey = "") {
        const objectsUrl = `${this._config.api_key_url}universes/${this._config.universe_id}/orderedDataStores/${datastore}/scopes/${scope}/entries`;
        const headers = { 'x-api-key': this._config.api_key };
        const params = { max_page_size: pageSize, order_by: orderBy, filter: filter, page_token: "" };
        return axios.get(objectsUrl, { headers, params });
    }

    create(datastore, scope, entry, data) {
        const objectsUrl = `${this._config.api_key_url}universes/${this._config.universe_id}/orderedDataStores/${datastore}/scopes/${scope}/entries`;
        const headers = this._H();
        const payload = { value: 11 };
        return axios.post(objectsUrl, payload, { params: { id: entry }, headers });
    }

    increment(datastore, scope, entry, incrementBy) {
        const objectsUrl = `${this._config.api_key_url}universes/${this._config.universe_id}/orderedDataStores/${datastore}/scopes/${scope}/entries/${entry}:increment`;
        const headers = { 'x-api-key': this._config.api_key };
        const payload = { amount: 1 };
        return axios.post(objectsUrl, payload, { headers });
    }
}

// Example usage:
const dataStores = new DataStores('config_file.json');

// Use the DataStores methods as needed, for example:
dataStores.list('yourDataStore', 'yourScope').then(response => {
    console.log(response.data);
});

I figured it out by using a different method, but this will work for others so I will give u the solution, thanks!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.