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
У кого-нибудь ещё возникает эта проблема прямо сейчас? Я уже два дня пытаюсь использовать API, но каждый раз получаю похожие ошибки. Не уверен, что я упускаю какой-то шаг или что-то изменилось.
Я создал новый API-ключ для пользователя system. Также пробовал создать API-ключ для всех пользователей, а затем использовать свою учётную запись администратора.
При использовании Ruby-библиотеки discourse_api:
DiscourseApi::UnauthenticatedError ({"errors"=>["Вы не имеете права просматривать запрошенный ресурс. Имя пользователя API или ключ недействительны."], "error_type"=>"invalid_access"})
Также пробовал использовать API, передавая api_username и api_key в данных формы вместе с необработанным запросом, но получаю ошибку 404.
Я пытаюсь написать скрипт, который читает список адресов электронной почты, получает имена пользователей, а затем отписывает их от всех рассылок Discourse.
Для ошибки, с которой вы столкнулись при работе с чистым Ruby-кодом, проблема заключается в том, что заголовки запроса должны содержать Api-Key и Api-Username. Имена полей API также должны использовать дефисы (-) вместо подчёркиваний (_). Подробную информацию об аутентификации запроса см. в разделе «Authentication» в верхней части страницы https://docs.discourse.org/.
Не уверен, что вызывает ошибку при вызове через gem Discourse API. Наиболее вероятная причина — использование неверных учётных данных API. Убедитесь, что вы используете ключ API, у которого уровень пользователя установлен как «All Users»: