Datastore API for node js

Datastore API for node js

Using the code below, you can both get and set data using the roblox datastore API.

If you are wondering how you download axios, just run the code

npm install axios



Here is the code:

const axios = require('axios').default;
const cookie = 'ROBLOSECURITY HERE';

const getAsync = async (placeId, name, scope, key) => {
    let response = {}
    try {
        response = (await axios.request({
            method: 'POST',
            url : `https://gamepersistence.roblox.com/persistence/getV2?placeId=${placeId}&type=standard&scope=${scope}`,
            headers : {
                'Cookie' : `.ROBLOSECURITY=${cookie}`,
                'Roblox-Place-Id' : toString(placeId),
                'Content-Type' : 'application/x-www-form-urlencoded',
                'User-Agent' : 'Roblox/WinInet'
            },
            data : `qkeys[0].scope=${scope}&qkeys[0].target=${key}&qkeys[0].key=${name}`
        }))
    } catch (err) {
        response = await getAsync(name, scope, key)
    }
    if (response && response.data && response.data.data && response.data.data[0] && response.data.data[0].Value) {
        return response.data.data[0].Value
    }
}

const setAsync = async (placeId, name, scope, key, value) => {
    try {
        await axios.request({
            method: 'POST',
            url : `https://gamepersistence.roblox.com/persistence/set?placeId=${placeId}&type=standard&key=${name}&type=standard&scope=${scope}&target=${key}&valueLength=${value.length}`,
            headers : {
                'Cookie' : `.ROBLOSECURITY=${cookie}`,
                'Roblox-Place-Id' : toString(placeId),
                'Content-Type' : 'application/x-www-form-urlencoded',
                'User-Agent' : 'Roblox/WinInet'
            },
            data : `value=${value}`
        })
    } catch (err) {
        await setAsync(name, scope, key, value)
    }
}
3 Likes

this is great but I recommend storing cookie inside .env file because its more secure if you are hosting it on replit

Theres a video tutorial on how to hide keys using environment variable. You will need to install dotenv and create a new .env file

This is the video 3.4 Hiding API Keys with Environment Variables (dotenv) and Pushing Code to GitHub - YouTube

1 Like

I just run it inside a local node environment, so no need. Thanks for the suggestion though.

1 Like