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)
}
}