Help using the presence API [Python]

Good day,

I’ve been trying to use Roblox’ new presence API to check an users last online date; however, I have only received error statements so far.
My code looks like this:

import requests

headers = {
    'Content-Type': 'application/json',
    'Accept': 'application/json',
}

data = {
  "userIds": [
    1843923756 
  ]
}

response = requests.post('https://presence.roblox.com/v1/presence/users', headers=headers, data=data)
print(response.text)

The cURL outputted by the API docs looks like this:

   "userIds": [ \ 
     1843923756 \ 
   ] \ 
 }' 'https://presence.roblox.com/v1/presence/users'

The Python code gives me the following error:

{"errors":[{"code":0,"message":"Invalid Request, user Ids cannot be null.","userFacingMessage":"Something went wrong"}]}

This seems quite bizarre to me, as I’ve clearly defined the userIds, does anyone see where I went wrong?

Thanks in advance!

The data you send needs to be in JSON format like so:

import json
import requests

headers = {
    'Content-Type': 'application/json',
    'Accept': 'application/json',
}

data = {
  "userIds": [
    1843923756 
  ]
}

response = requests.post('https://presence.roblox.com/v1/presence/users', headers=headers, data=json.dumps(data))
print(response.text)
1 Like

Thank you for the quick reply, your solution worked perfectly!

1 Like

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