Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Api's return with UnsupportedMediaType

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading