A user, erik_chan, is experiencing an error (“You are not permitted to view the requested resource”) when trying to access a private category using the Ruby API. They have tried authenticating with different users, including the system user, but still encounter the issue.
erik_chan mentions that they expect users with admin rights to be able to access private categories via the API.
Other users, such as chenny408 and j127, report similar issues.
simon suggests that the problem might be due to incorrect API credentials or authentication method. They point out that the Api-Key and Api-Username need to be set in the request headers, and the API field names should use dashes (-) instead of underscores (_).
j127 confirms that setting the Api-Key and Api-Username in the request headers resolves the issue. They also mention that the Discourse API documentation might need to be updated to reflect this.
simon updates the relevant documentation and deletes outdated posts.
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.
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
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:
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: