i can’t get around using json to insert data into an api call.
I tried some simple code but it just doesn’t work
import json
import requests
url = "https://presence.roblox.com/v1/presence/users"
body = json.dumps({"userIds": [1]})
response = requests.post(url, data=body)
presence = response.json()
print(presence)
im trying to set a parameter "userIds" so i can list the ids i want to check with the API, but im just confused.
error message: {‘errors’: [{‘code’: 0, ‘message’: ‘UnsupportedMediaType’}]}
>Solution :
Server expects the request body to be in JSON format. You Have to specify the content-type.
import json
import requests
url = "https://presence.roblox.com/v1/presence/users"
# Specify JSON content type
headers = {
'Content-Type': 'application/json'
}
body = json.dumps({"userIds": [1]})
response = requests.post(url, headers=headers, data=body)
presence = response.json()
print(presence)