I have three functions to help me with submitting requests to the CloudAPI to update data that’s stored with ProfileService. From the javascript end, it seems to update the data, but when I load into studio, my entire ProfileService data is corrupted and resets all data as if I’m a new player.
I’m new to using the cloud with datastores so I’m not sure if I’m doing something wrong.
fetchData Function:
async function fetchData(playerID) {
try {
const response = await fetch(`https://apis.roproxy.com/datastores/v1/universes/${UNIVERSE_ID}/standard-datastores/datastore/entries/entry?datastoreName=RTSData&entryKey=Key1_${playerID}`, {
headers: { "x-api-key": API_KEY }
});
if (response.ok) {
console.log(response)
const data = await response.json();
return data.Data
} else {
console.log('Fetch failed with status:', response.status, response.statusText);
return null;
}
} catch (error) {
console.log('Error fetching data:', error);
return null;
}
}
updateData Function
async function updateData(playerID, updatedData) {
try {
const response = await fetch(`https://apis.roproxy.com/datastores/v1/universes/${UNIVERSE_ID}/standard-datastores/datastore/entries/entry?datastoreName=RTSData&entryKey=Key1_${playerID}`, {
method: 'POST',
headers: { "x-api-key": API_KEY, "Content-Type": "application/json" },
body: updatedData
});
if (response.ok) {
const result = await response.json();
return result;
} else {
console.log('Update failed with status:', response.status, response.statusText);
return null;
}
} catch (error) {
console.log('Error updating data:', error);
return null;
}
}
modifyData Function
async function modifyData(playerID) {
try {
const currentData = await fetchData(playerID);
if (currentData) {
currentData.Statistics.Reputation = 100;
currentData.Statistics.Wins = 100;
const updateResult = await updateData(playerID, currentData);
console.log(fetchData(playerID))
} else {
console.log('No data to modify.');
}
} catch (error) {
console.log('Error modifying data:', error);
}
}
And simply to begin the process, I call the modifyData()
function as such: modifyData(userID)