API Error: You are not permitted to view the requested resource

I am receiving the following error:

DiscourseApi::UnauthenticatedError: 
{"errors"=>["You are not permitted to view the requested resource."], "error_type"=>"invalid_access"}

when I make the ruby API call ‘category_latest_topics’

response = client.category_latest_topics("<some_category>") 

This is due to the category permissions (the category is not public). I tried to authenticate by using

client.api_username = "system"  

and making sure “system” is a member of the group that has permissions to the category but still no luck! Any suggestions or workarounds?

2 Me gusta

No response so far. Am I posting this in the right forum?

Try using a different user, other than System. Issue an API key for a different user. You will need to experiment.

No luck. Tried issuing API key for different users who have permission to the category but still no access.

Would be awesome if anyone else has suggestions for this?

How can I access a private category via the API. This should not be an issue for users/system with admin rights to the forum.

I’m having the same issue, can someone take a look into this?

1 me gusta

Have you attempted to generate a key from your account? You are the admin who created the forum, yes? You say “users/system” so I am wondering if you tried your own account.

Yes i am the admin of my forum.

I have tried both my username and system with no luck. I can’t call client.category_latest_topics(<category_name>) even though the user has permissions to the category

I feel some other variable exists and is causing this error; one that cannot be seen due to the limited info provided.

Be sure to check these topics in regards to setting up and using the Discourse API, if you have not yet done so.

Appreciate your help. If you read my original post i am using the ruby api. I have also looked through the documentation before posting this topic.

If you could show me what variable i am missing or where to exactly to find out more i would appreciate it.

1 me gusta

¿Alguien más está experimentando este problema en este momento? He estado intentando usar la API durante dos días, pero cada vez obtengo errores similares. No estoy seguro de si me estoy saltando algún paso o si ha cambiado algo.

He creado una nueva clave de API para el usuario system. También intenté crear una clave de API para todos los usuarios y luego usar mi cuenta de administrador.

Usando el gem de Ruby discourse_api:

DiscourseApi::UnauthenticatedError ({"errors"=>["No tiene permiso para ver el recurso solicitado. El nombre de usuario o la clave de la API no son válidos."], "error_type"=>"invalid_access"})

También intenté con este código de otra publicación:

require 'net/http'
require 'uri'

INSTANCE_URL = 'https://forum.example.com/admin/users/list/all.json?email=user@example.com'
API_USERNAME = 'system'
API_KEY = 'una_nueva_clave_de_api_aquí'

def send_request
  url = URI.parse(INSTANCE_URL)
  request = Net::HTTP::Get.new(url.path)
  request.set_form_data({'api_username' => API_USERNAME, 'api_key' => API_KEY})
  http = Net::HTTP.new(url.host, url.port)
  response = http.request(request)

  if response.code == '200'
    puts "¡Éxito!"
  else
    puts "Error"
    puts response.code
  end
end

send_request # 400

También intenté usar la API incluyendo api_username y api_key en los datos del formulario junto con una solicitud en bruto, pero obtengo un error 404.

Estoy intentando escribir un script que lea una lista de direcciones de correo electrónico, obtenga los nombres de usuario y luego los dé de baja de todos los correos electrónicos de Discourse.

Para el error que estás obteniendo con el código Ruby sin procesar, el problema es que Api-Key y Api-Username deben establecerse en las cabeceras de la solicitud. Los nombres de los campos de la API también deben usar guiones (-) en lugar de guiones bajos (_). Consulta la sección de Autenticación en la parte superior de https://docs.discourse.org/ para obtener detalles sobre cómo autenticar la solicitud.

No estoy seguro de qué podría estar causando el error al realizar la llamada con la gem de la API de Discourse. La causa más probable del problema es que no estás utilizando las credenciales de API correctas. Asegúrate de usar una clave de API cuyo Nivel de Usuario esté configurado en Todos los usuarios:

Si eso no resuelve el problema, publica aquí la solicitud que estás intentando realizar y la revisaré.

5 Me gusta

Gracias, eso funciona. Estaba siguiendo los primeros par de publicaciones aquí, que podrían necesitar una actualización:

2 Me gusta

Gracias por señalarlo. He actualizado la publicación original y eliminado los posts más antiguos del tema.

3 Me gusta