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
Alguém mais está enfrentando esse problema no momento? Tenho tentado usar a API há dois dias, mas sempre recebo erros semelhantes. Não tenho certeza se estou pulando alguma etapa ou se algo mudou.
Criei uma nova chave de API para o usuário system. Também tentei criar uma chave de API para todos os usuários e, em seguida, usar minha conta de administrador.
Usando a gem Ruby discourse_api:
DiscourseApi::UnauthenticatedError ({"errors"=>["Você não tem permissão para visualizar o recurso solicitado. O nome de usuário ou a chave da API são inválidos."], "error_type"=>"invalid_access"})
Também tentei usar a API inserindo o api_username e o api_key nos dados do formulário junto com uma solicitação bruta, mas recebo um erro 404.
Estou tentando escrever um script que lê uma lista de endereços de e-mail, obtém os nomes de usuário e, em seguida, os cancela de todos os e-mails do Discourse.
Para o erro que você está recebendo com o código Ruby puro, o problema é que Api-Key e Api-Username precisam ser definidos nos cabeçalhos da solicitação. Os nomes dos campos da API também precisam usar hífens (-) em vez de sublinhados (_). Consulte a seção de Autenticação no topo de https://docs.discourse.org/ para detalhes sobre como autenticar a solicitação.
Não tenho certeza do que estaria causando o erro ao fazer a chamada com a gem Discourse API. A causa mais provável do problema é que você não está usando as credenciais de API corretas. Certifique-se de estar usando uma chave de API cujo Nível de Usuário esteja definido como Todos os Usuários: