Help with ProfileSevice & OpenCloud

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)

Why are you using roproxy? You can just go directly to the Roblox site

1 Like

It would error because your not returning the full table only the Data of the profile

1 Like

I don’t think that’s the issue.

1 Like

It is because profile service has loads of extra information outside of that data value and your just wiping it causing the corruption

So I’m guessing it won’t be possible with ProfileService?

ProfileService stores your actual data inside the key Data, don’t just save Data by itself as you are removing internal keys used by ProfileService. You can double check if this is correct by printing out what gets returned by fetchData.

Change your fetchData to return data and access your data via currentData.Data.