Using POST on datastores

I’m not entirely sure how to describe the problem I’m having, but I’m trying to make a discord bot that allows for me to edit my datastores. (for moderation without having to join the game etc)

In specific, when trying to make a ban command I ran into a problem where the “content-md5” has to be a string and cannot be an array, or atleast I’m pretty sure this is the case. I need it to be an array so I can use:

{false --[[is the player banned]], banGUID}

I also barely understand what an md5 is.

The current way im trying to do (cURL)

curl --request POST "https://apis.roblox.com/datastores/v1/universes/x/standard-datastores/datastore/entries/entry?datastoreName=BannedPlayers&entryKey=TEST"
--header "x-api-key: x"
--header "content-md5: [ARRAY HERE]" \
--header "content-type: application/json" \
--header "roblox-entry-userids: [269323]" \
--header "roblox-entry-attributes: {}" \
--data-ascii idk

Anything helps.
Thanks

3 Likes

With the API you’ve provided I don’t think there would be anyway for it to know what games datastore you want to access and weather you’ve actually got permission to edit the games datastore.

Just did a little search, and apparently its not currently possible.

1 Like

ive seen a usage of it before and my current ““working”” version allows for this
image

1 Like

I don’t exactly know for sure but, that image you’ve sent is getting the datastore not updating the datastore.

1 Like

yeah, i know im able to update the datastore too, im just not sure if i can do it with anything other than strings

1 Like

Wait do you already have the script that updates the datastore working but with strings?

1 Like

yes, im not really sure how to explain what im doing but it ONLY allows for setting values to strings as far as im aware, because im not sure if or how to md5 encode an array

1 Like

Are you able to send the working script and I’ll take a look?

1 Like

do you mean the discord python script or the cURL?

1 Like

Uhh, maybe both and the Roblox one?

I don’t know python well or what cURL is but I can try my best.

Have you also tried to setting values to strings, numbers, etc?

1 Like

there is no roblox script really besides checking if the player is banned on join, but here is the cURL script

curl --include --location --request POST “https://apis.roblox.com/datastores/v1/universes/UNIVERSEID/standard-datastores/datastore/entries/entry?datastoreName=BannedPlayers&entryKey=TEST
–header “x-api-key: x”
–header “content-md5: sTf90fedVsft8zZf6nUg8g==”
–header “content-type: application/json”
–header “roblox-entry-userids: [269323]”
–header “roblox-entry-attributes: {}”
–data-ascii 750

(if you want to run this yourself you can use this site, but you will need to have everything setup which i can help you through if youd like)

this sets the datastore value to 750
image
the way im needing it to be is
image
btw
(sending python in a minute)

1 Like

import requests
headers = {
‘x-api-key’: 'x,
‘content-md5’: ‘sTf90fedVsft8zZf6nUg8g==’,
# Already added when you pass json=
# ‘content-type’: ‘application/json’,
‘roblox-entry-userids’: ‘[269323]’,
‘roblox-entry-attributes’: ‘{}’,
}

params = {
    'datastoreName': 'BannedPlayers',
    'entryKey': 'TEST',
}

json_data = 750

response = requests.post(
    'https://apis.roblox.com/datastores/v1/universes/4768764041/standard-datastores/datastore/entries/entry?datastoreName=BannedPlayers&entryKey=TEST',
    params=params,
    headers=headers,
    json=json_data,
)
print(response.text)

sorry if the code is not so great i just self taught myself python over the last like 2 hours :sweat_smile:

1 Like

while reading into this just now im thinking i might be able to use a json encoded table, i can try it but im not sure if it will work

1 Like

Try change this to

json_data = {
     Money = 750
     Banned = false
     Rank = "Admin"
}

Lol this is just a random guess because I’m clueless about python. Maybe this’ll work or maybe not but go for the json encoded table like you said if it doesn’t work.

1 Like

this is the “content length” part of it which for some reason isnt put as a header, but i can try it

heres what ive been looking at https://create.roblox.com/docs/reference/cloud/datastores-api/v1#POST-v1-universes-universeId-standard-datastores-datastore-entries-entry

1 Like

Are you wanting to make a brand new table or update a table?

Is this just for one piece of data or multiple?

1 Like

It just replaces the old value so i guess new table
what do you mean one piece/multiple pieces?

also i just realized content-md5 is not required but it increases corruption chance so give me one second

1 Like

You might be able to update a current table?

I’m meaning like is it updating a bunch of different things like bans, money, ranks, etc, or is it just updating bans?

FYI: Money and ranks were just examples.

1 Like

your a lifesaver i did NOT expect this to work but it did lol, thank you
image

1 Like

Did you not try that at first? lol

Also when it saves as 1) and 2) did you want that to be a custom index or just boring numbers fine?

1 Like