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?

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?

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.

Qualcun altro sta riscontrando questo problema in questo momento? Da due giorni provo a utilizzare l’API, ma ogni volta ottengo errori simili. Non sono sicuro di aver saltato un passaggio o se sia cambiato qualcosa.

Ho creato una nuova chiave API per l’utente system. Ho anche provato a creare una chiave API per tutti gli utenti e poi ho usato il mio account amministratore.

Usando il gem Ruby discourse_api:

DiscourseApi::UnauthenticatedError ({"errors"=>["Non sei autorizzato a visualizzare la risorsa richiesta. Il nome utente o la chiave API non sono validi."], "error_type"=>"invalid_access"})

Ho anche provato con questo codice tratto da un altro post:

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_nuova_chiave_api_qui'

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 "Successo!"
  else
    puts "Errore"
    puts response.code
  end
end

send_request # 400

Ho anche provato a utilizzare l’API inserendo api_username e api_key nei dati del modulo insieme a una richiesta grezza, ma ottengo un errore 404.

Sto cercando di scrivere uno script che legga un elenco di indirizzi email, ottenga i nomi utente e poi li disiscriva da tutte le email di Discourse.

Per l’errore che stai riscontrando con il codice Ruby grezzo, il problema è che Api-Key e Api-Username devono essere impostati negli header della richiesta. Anche i nomi dei campi dell’API devono utilizzare trattini (-) invece di sottolineature (_). Consulta la sezione Autenticazione in alto su https://docs.discourse.org/ per i dettagli su come autenticare la richiesta.

Non sono sicuro di cosa stia causando l’errore quando effettui la chiamata con il gem Discourse API. La causa più probabile del problema è che non stai utilizzando le credenziali API corrette. Assicurati di utilizzare una chiave API il cui livello utente sia impostato su Tutti gli utenti:

Se ciò non risolve il problema, pubblica qui la richiesta che stai tentando di effettuare e la controllerò.

Grazie, funziona. Stavo seguendo i primi due post qui, che potrebbero aver bisogno di un aggiornamento:

Grazie per averlo segnalato. Ho aggiornato l’OP e cancellato i post più vecchi dal topic.