About DataStore open cloud key

I’m planning to make something using Open Cloud and DataStores.

Is there a way I can limit what datastores the thing can access?
Thanks!

Yes, you can! When configuring the API key, you’ll have the option to limit it to certain data stores. To do this you must:

  1. Add the universe-datastores API system to the key, if you haven’t already.
  2. Toggle on ‘Restrict by Experience’ and find the target game.
  3. They’ll be another toggle appear ‘specific data store operations for Experience [experience name]’. Toggle this on as well.
  4. If you press ‘Search for your data stores,’ a case sensitive search bar will appear and you can find the data store and add it.
  5. Once added, you can add scopes to that particular data store.

For instance, in the image below this API key can read keys in all data stores and list data stores in the experience. Further, the key can read keys version, create, and update keys but only in the PlayerData data store.

Remember, it’s always good practise to give the minimum privileges to an API key, so if it is only updating existing keys, it doesn’t need permission to create or delete keys. Happy coding!

1 Like

Make sure to remove the scopes from the entire experience or all of them will be accessible. You can see how one of the specific operations are grayed because it’s covered by a larger granted operation over the entire experience instead of that specific data store.

1 Like

hi, a little while ago i actually tried this but for some reason, every time i try to read the key via python [i suck at python so im sorry, i had to use some ai for this as a rough test, i promise i won’t use ai in the future i dont use ai for anything else], it doesnt seem to be working. why is this?

import requests
import json

# ==== CONFIGURE THESE ====
API_KEY = ""  # never share this
UNIVERSE_ID = 6991496486           # your universe ID as an integer
DATASTORE_NAME = "4X7B9KQ2M8T1LZ6W3YD0Z5N8C"
SCOPE = "global"                   # or "" if you don't use scopes
ENTRY_KEY = "1"
# =========================

url = f"https://apis.roblox.com/datastores/v1/universes/{UNIVERSE_ID}/standard-datastores/datastore/entries/entry"

params = {
    "datastoreName": "4X7B9KQ2M8T1LZ6W3YD0Z5N8C",
    "scope": "global",
    "key": "1",
}

headers = {
    "x-api-key": API_KEY,
}

response = requests.get(url, headers=headers, params=params)

print("Status code:", response.status_code)
print("Using API key:", API_KEY)
if response.ok:
    # Roblox may return JSON or raw data depending on what you stored.
    # Try to decode JSON, fall back to raw text.
    try:
        data = response.json()
        print("Value for key '1' (JSON):")
        print(json.dumps(data, indent=2))
    except json.JSONDecodeError:
        print("Value for key '1' (raw):")
        print(response.text)
else:
    print("Error response body:")
    print(response.text)
print(params["scope"])
print(response)


i mean IP restrictions arent even enabled and it just spits out error code 400

The issue here is with key, according to the docs, it expects entryKey here instead. Easy mistake to make that’s all good.

I’ve dealt with the API a lot and actually made an API wrapper for it that you could find easier to use as I made it with less experienced programmers in mind. Your code sample would look simpler like this instead:

from rblxopencloud import Experience

# ==== CONFIGURE THESE ====
API_KEY = ""  # never share this
UNIVERSE_ID = 6991496486           # your universe ID as an integer
DATASTORE_NAME = "4X7B9KQ2M8T1LZ6W3YD0Z5N8C"
SCOPE = "global"                   # or "" if you don't use scopes
ENTRY_KEY = "1"
# =========================

experience = Experience(UNIVERSE_ID, API_KEY)

datastore = experience.get_datastore(DATASTORE_NAME, scope=SCOPE)

value, info = datastore.get_entry(ENTRY_KEY)
print(value)

Also, I’d just like to point out, like @wiremass did, I didn’t communicate how to set the scopes very well and accidentally caused confusion. I’d like to clarify that with your scopes, you don’t select them in the top box but only in the bottom boxes. So on your page you’d remove them from here:


My apologies for that miscommunication.

1 Like

ah, don’t worry about the scopes!
i was being so frantic so i tried to enable everything [in a seperate screenshot] on all the stores, and etc.. and it somehow STILL didn’t work, and i was just going crazy lol

thank you so much!

1 Like

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